Week 4. Sep 12.19 2018 - michelle-qin/Portfolio GitHub Wiki

Still working on the perpetual motion staircase. Ran the test code, bumped into errors (code couldn't identify "Stepper") and realized that I do not have the updated version. Went onto DPEA's github and learned to clone Project-Examples and RaspberryPiCommons.

Continued to run into errors after cloning the updated versions of code. Ran "i2cdetect -y 1" which printed out more alerts than expected - seems like something was in a loop. Worked with Mr. Harlow and discovered there was a thermo component on the arduino that was soldered incorrectly. Removed it and "i2cdetect -y 1" resulted in the expected number of alerts, but the staircase was still not working.

Checking the code bit by bit. Hooked a LED onto the arduino and wrote the code below to test if it would turn the LED on and off:

while(1): SlushEngine.setIOState(0, 3, 1) SlushEngine.setIOState(0, 2, 1) SlushEngine.setIOState(0, 3, 0) SlushEngine.setIOState(0, 2, 0) time.sleep(1)

Worked on the "1 Calorie Workout" with my partner, Albert. Specifically, the raspberrypi sensor on the current model is too slow to detect a mint falling past it. We worked on creating a new and more sensitive sensor using Cypress that could detect the mint faster and be implemented in the model. Learned the logic behind circuits, gates, and flow-chart diagram on Cyrpess. The code was written so that when an object (i.e. a mint) passed the sensor, an LED would turn on; when a button is pressed, the LED would turn off. As we ran the code, we realized a problem: the LED seemed to be turning off at random times without pressing the button.

After trouble-shooting, we narrowed the error down to a hardware issue (seemed like the board/button was too-sensitive to touch - even if our finger was near the button, the LED would turn off without a button press) or a software issue (Albert had implemented a gate earlier that was designed to prevent the LED turning off in response to other variables - ex: while LED was turned on, when shadows passed by sensor). Finally, realized the issue was with Albert's gate.

images/SensorMaterials.JPG A photo of the materials that we used for the "1 Calorie Workout" sensor

Began working on Perpetual Motion. Downloaded Geany. 1st issue: ramp was crashing into one end. Went into the code, realized the direction of the ramp was reversed (i.e. when the ramp was going to the top, it was coded to go home/to the bottom). Updated it (see below):

rampLength = 730 ramp = Stepper.Stepper(port = 0, speed = 100) ramp.home(0)

def homeRamp(self, isHome):
    if (isHome == HOME):
        self.ids.ramp.text = "Ramp To Top"
        print('ramp home') 
        ramp.home(0)
    else:
        self.ids.ramp.text = "Ramp Home"

2nd issue: gate opening/closing error. Realized that port 4 was actually reading to port 7. Updated the code (see below):

def openGate(self, isOpen):
    if (isOpen == OPEN):
        self.ids.gate.text = "Close Gate"
        print('close gate')
        RPiMIB.sendPWM(7, 3500)
    else:
        self.ids.gate.text = "Open Gate"
        print('open gate')
        RPiMIB.sendPWM(7, 1000)
    self.isGateOpen = isOpen

Worked with mentor Doug to stabilize the issue by going into the RPiMIB.py and added spi.mode = 0. By adding this line, we can change the code to reflect the accurate port. See code below.

def openSPI(): spi.open(0,0) spi.mode = 0

Above code in main.py was changed to:

def openGate(self, isOpen):
    if (isOpen == OPEN):
        self.ids.gate.text = "Close Gate"
        print('close gate')
        RPiMIB.sendPWM(4, 1000)
    else:
        self.ids.gate.text = "Open Gate"
        print('open gate')
        RPiMIB.sendPWM(4, 3500)
    self.isGateOpen = isOpen

Now, we have the 3 separate components working on UI: Open/Close Gate, On/Off Staircase, Home/Top Ramp.

3rd issue: "Start" process When we run the entire process by touching "Start" on UI, the ramp and gate work at the right time, but the staircase seems to be off (i.e. not turning on when we want it to/when the ball reaches it). Currently working on fixing this.