User avatar
QBall1977
Posts: 77
Joined: Thu Aug 09, 2012 10:06 am
Location: Hull, East Yorkshire
Contact: Website

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Sat May 17, 2014 12:26 am

Any chance you can help. I'm an Arduino newbie. But basically I followed another tutorial to hack some IKEA DIODER Lights, you remove the controller, wire to Red, Green, Blue, a common ground and common +5v. The following .ino works when uploaded via the Arduino IDE... :P
**********************************************************************************************

Code: Select all

// color swirl! connect an RGB LED to the PWM pins as indicated
// in the #defines
// public domain, enjoy!

#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3

#define FADESPEED 5 // make this higher to slow down

void setup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
}

void loop() {
int r, g, b;

// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}

// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
}
I was hoping to have similar control over the LEDs using the PyMata, however I'm having trouble finding an example that uses PWM and allows analog writes. :?

I thought something like this would work but it seems to output nothing. Do you have any suggestions?

***************************************************************************************

Code: Select all

import time

from PyMata.pymata import PyMata
# Give the pins names:
REDPIN = 5
GREENPIN = 6
BLUEPIN = 3

FADESPEED = 5

# Create an instance of PyMata.
SERIAL_PORT = "/dev/ttyS0"
firmata = PyMata( SERIAL_PORT, max_wait_time=5 )

# initialize the digital pin as an output.
#firmata.set_pin_mode( LED, firmata.OUTPUT, firmata.DIGITAL )
firmata.set_pin_mode( REDPIN, firmata.OUTPUT, firmata.PWM)
firmata.set_pin_mode( GREENPIN, firmata.OUTPUT, firmata.PWM)
firmata.set_pin_mode( BLUEPIN, firmata.OUTPUT, firmata.PWM)

try:
# run in a loop over and over again forever:
while True:
#for r in range (0,256,1):
firmata.analog_write( REDPIN, 255 )
firmata.analog_write( GREENPIN, 0 )
firmata.analog_write( BLUEPIN, 255 )
time.sleep(1.0) # wait for a second

except KeyboardInterrupt:

# Catch exception raised by using Ctrl+C to quit
pass

# close the interface down cleanly
firmata.close()
Sorry, should have posted it like this in the first place. Apologies.

Mark.

abroun
Posts: 31
Joined: Sat Jun 29, 2013 10:13 am
Contact: Website

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Sat May 17, 2014 12:45 pm

Hi there,

If you're still having a problem with this then I think that you're almost there, you should just need to set the pins to ANALOG rather than PWM. So the following should hopefully work (no Pi Co-op or Arduino on hand to test this at the moment)

Code: Select all

# initialize the pins as analog output.
firmata.set_pin_mode( REDPIN, firmata.OUTPUT, firmata.ANALOG )
firmata.set_pin_mode( GREENPIN, firmata.OUTPUT, firmata.ANALOG )
firmata.set_pin_mode( BLUEPIN, firmata.OUTPUT, firmata.ANALOG )
The documentation for PyMata is a bit sparse, but if you scroll down you should see a bit more detail on using set_pin_mode.

Hope that helps.

Regards

Alan

User avatar
QBall1977
Posts: 77
Joined: Thu Aug 09, 2012 10:06 am
Location: Hull, East Yorkshire
Contact: Website

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Sat May 17, 2014 10:54 pm

Alan,

Thanks for the swift response, I appreciate you taking the time. I tried what you suggested however I get the following error. I thought I had issues with the pin numbers, should these be the same as stated on the Pi CO-OP board? (they're the PWM3, PWM5, PWM6 pins)

Here's the error.

Code: Select all

Opening Arduino Serial port /dev/ttyS0
Please wait while Arduino is being detected. This can take up to 5 seconds ...
Board initialized in 0 seconds
Total Number of Pins Detected = 20
Total Number of Analog Pins Detected = 6
Traceback (most recent call last):
  File "MRO_DIODER.py", line 18, in <module>
    firmata.set_pin_mode( GREENPIN, firmata.OUTPUT, firmata.ANALOG)
  File "/home/pi/PyMata/PyMata/pymata.py", line 718, in set_pin_mode
    self._command_handler.analog_response_table[pin][self._command_handler.RESPONSE_TABLE_MODE] = mode
IndexError: list index out of range
Exception in thread Thread-1 (most likely raised during interpreter shutdown):Exception in thread Thread-2 (most likely raised during interpreter shutdown):

Traceback (most recent call last):Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
  File "/home/pi/PyMata/PyMata/pymata_serial.py", line 106, in run
  File "/home/pi/PyMata/PyMata/pymata_command_handler.py", line 698, in run
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 432, in inWaiting
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'unpack'
I wish I was more familiar with arduinos, perhaps the pins should be referred to differently when using PyMata?

Any further suggestions?

Thanks in advance.

Mark.
____________________________________________
Looking for where to start - try Kernel Panic - http://goo.gl/EEQ5J

User avatar
QBall1977
Posts: 77
Joined: Thu Aug 09, 2012 10:06 am
Location: Hull, East Yorkshire
Contact: Website

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Sat May 17, 2014 11:39 pm

A bit of additional information, this error seems to be when setting PIN 6. So I commented this out. The remaining code still does nothing. :? I can't see why the original INO file works and this does not.

Code: Select all

import time

from PyMata.pymata import PyMata
# Give the pins names:
REDPIN = 5
GREENPIN = 6
BLUEPIN = 3

FADESPEED = 5

# Create an instance of PyMata.
SERIAL_PORT = "/dev/ttyS0"
firmata = PyMata( SERIAL_PORT, max_wait_time=5 )

# initialize the digital pin as an output.
firmata.set_pin_mode( REDPIN, firmata.OUTPUT, firmata.ANALOG)
#firmata.set_pin_mode( GREENPIN, firmata.OUTPUT, firmata.ANALOG)
#firmata.set_pin_mode( BLUEPIN, firmata.OUTPUT, firmata.PWM)

try:
    # run in a loop over and over again forever:
    while True:
        firmata.analog_write( REDPIN, 255 )
#       firmata.analog_write( GREENPIN, 255 )
#       firmata.analog_write( BLUEPIN, 255 )
        time.sleep(1.0) # wait for a second

except KeyboardInterrupt:

    # Catch exception raised by using Ctrl+C to quit
    pass

# close the interface down cleanly
firmata.close()
____________________________________________
Looking for where to start - try Kernel Panic - http://goo.gl/EEQ5J

abroun
Posts: 31
Joined: Sat Jun 29, 2013 10:13 am
Contact: Website

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Mon May 19, 2014 2:51 pm

Hi there,

First of all, apologies that my first reply didn't work. I think the key lesson here is not to offer advice without having the hardware to test it. :oops:

Now reading through the PyMata and Firmata source code a bit more carefully, it looks like the lines you actually want here are

Code: Select all

# initialize the pins as analog PWM.
firmata.set_pin_mode( REDPIN, firmata.PWM, firmata.DIGITAL )
firmata.set_pin_mode( GREENPIN, firmata.PWM, firmata.DIGITAL )
firmata.set_pin_mode( BLUEPIN, firmata.PWM, firmata.DIGITAL )
I have tested this with pins 3, 5, and 6 and they all seem to produce the correct PWM signals when you use analog_write. I think that the main problem here is that that particular PyMata routine isn't that clear, or well documented. The DIGITAL/ANALOG setting only seems to have an effect when the pins are used as inputs, or as digital outputs...

Hope that helps.

Regards

Alan

User avatar
QBall1977
Posts: 77
Joined: Thu Aug 09, 2012 10:06 am
Location: Hull, East Yorkshire
Contact: Website

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Mon May 19, 2014 6:45 pm

Alan,

Thanks for your response, that worked a treat! I can also confirm that Nanpy works with the Pi CO-OP. Despite some misleading documentation and few problems installing into python. That worked well too. (see example below, of course you have to download the Nanpy to the Arduino first!)

Code: Select all

from nanpy import Arduino
from nanpy import SerialManager
from time import sleep

#serial_manager.connect('/dev/ttyS0')        # serial connection to Arduino
connection = SerialManager()
a = Arduino(connection=connection)
a.pinMode(5, a.OUTPUT)
a.pinMode(6, a.OUTPUT)
a.pinMode(3, a.OUTPUT)

RLED = 5                        # LED on Arduino Pin 10 (with PWM)
GLED = 6
BLED = 3

print"Starting"
print"5 blinks"

a.digitalWrite(BLED,a.LOW)
a.digitalWrite(GLED,a.LOW)

for i in range(0,5):
    Arduino.digitalWrite(RLED, Arduino.HIGH)
    sleep(0.5)
    Arduino.digitalWrite(RLED, Arduino.LOW)
    sleep(0.5)

print"Changing brightness of LED"
bright = 128                           # Mid brightness
a.analogWrite(RLED, bright)
#a.digitalWrite(LED,a.HIGH)          # Turn on LED
for i in range(0,200):
    bright = bright + 8
    if (bright > 200):          # LED already full on at this point
        bright = 0          # Minimum power to LED
    a.analogWrite(RLED, bright)           # Change PWM setting/brightness
    sleep(0.5)

a.digitalWrite(RLED,a.LOW)          # Turn off LED
print"Finished"
____________________________________________
Looking for where to start - try Kernel Panic - http://goo.gl/EEQ5J

64BR1
Posts: 1
Joined: Mon Jul 07, 2014 8:41 am

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Mon Jul 07, 2014 8:44 am

Hello!
I would like to control this co-op card with a program done in c++. Is there any library to do it? where can I find it?
Thanks

dhester
Posts: 20
Joined: Mon Jul 16, 2012 8:35 pm

Re: The Pi Co-op - an Arduino Add-on Board for the Raspberry

Sat May 28, 2016 7:11 pm

I know this is a bit old but does anyone have the tutorial as the site is down as Dawn has shut down.

Return to “For sale”