Calamari

The Calamari lure makes use of may of the signals on the MinnowBoard Low Speed Expansion bus. In this example we will read from the Analog Digitcal Converter (ADC), visualize the data, and light an LED when the read value exceeds a threshold.

Import the modules and initialize the Calamari lure, then light the Red, Green, and Blue LEDs.


In [ ]:
from pyDrivers import calamari
c = calamari.calamari()

In [ ]:
c.led3.red(1)
c.led3.green(1)
c.led3.blue(1)

Collect Data

Verify that the value changes as you move the Calamari slider (potentiometer) through its range.

Click in the cell below and press ctrl+enter to see the value change.


In [ ]:
print c.adc.read()

Visualize Data

Now that you know it works, you can capture several values over a period of time and then plot that data. The next cell will record 50 samples (10 samples per second for 5 seconds). Run the cell below and move the slider through its range until it prints the 50 values.


In [ ]:
import time
adc_values = []
x = range(0, 200)
for i in x:
    adc_values.append(c.adc.read())
    time.sleep(0.01)
print adc_values

Now that we have collected the data, we can plot it using matplotlib.


In [ ]:
%pylab inline

plot(x, adc_values)

Seven Segment Display

Here we'll use the calamari's seven-segment display to write some basic characters. You can use any number from 0 to 9, and any character from A to F. You can put in individual characters, or a string. The second argument in the string function is how long to pause after displaying each character.


In [ ]:
c.sseg.putc("1")
time.sleep(1)
c.sseg.putc("2")
time.sleep(1)
c.sseg.putc("3")
time.sleep(1)
c.sseg.puts("ABC",1)

Threshold Indicator

We can establish a threshold value and indicate when the value read exceeds the threshold by lighting the red LED on the Calamari.


In [ ]:
for i in range(0,20):
    current_value = c.adc.read()
    if (0 <= current_value <= 400):
        c.sseg.putc("A")
        c.led3.blue(1)
        c.led3.red(0)
        c.led3.green(0)
    elif (401<= current_value <=901):
        c.sseg.putc("B")
        c.led3.red(1)
        c.led3.blue(0)
        c.led3.green(0)
    else:
        c.sseg.putc("C")
        c.led3.green(1)
        c.led3.blue(0)
        c.led3.green(0)
    c.led3.red(0)
    c.led3.blue(0)
    c.led3.green(0)

Buttons


In [ ]:
buttons = c.s1.wait()
print "Button 1 pressed!"
buttons = c.s2.wait()
print "Button 2 pressed!"
buttons = c.s3.wait()
print "Button 3 pressed!"

In [ ]: