The Pi Co-op is an addon board for the Raspberry Pi which brings the power of an Arduino microcontroller to our favourite single board computer.
Alan over at Dawn Robotics very kindly gave me a board to test. Apart from a brief session with the Gertduino I didn’t have much experience of Arduino programming.
Alan assured me it was easy …
What is the Pi Co-op?
The Pi Co-op combines the flexibility of the Pi with the microcontroller awesomeness of the Arduino. For timing critical applications the Arduino is king. By adding one to the Pi you get better control of analogue sensors that require an analogue to digitial convertion and devices that have time sensitive data buses. This includes LCD screens and NeoPixels.
Features
- Atmega328p microcontroller
- 10bit 8 channel ADC
- Can be programmed directly from the Pi using the free Arduino IDE
- UART baud rate of up to 115200bps
- Atmega328p pins broken out to female headers for easy prototyping
- Pi can be powered via board
- Standard pin spacing of 2.54mm on all headers
The full specification is on the official Pi Co-op product page including a link to the clearly presented user manual. The documentation (or lack of) is something that ended my experiments with the Gertduino.
Here is a Dawn Robotics video which gives a nice introduction to the board :
Step 1 – Initial Setup
Setting up the Pi Co-op only takes a few simple steps. Run the two commands below on the command line. Your Pi will need to be connected to the internet :
sudo apt-get update sudo apt-get install arduino git
This will install the Arduino IDE (this will allow you to send Arduino “sketches” to the device) and the Git software management system. .
Now run the following command to download the Pi Co-op resources :
git clone https://bitbucket.org/DawnRobotics/pi_co-op.git
In order to communicate with the device the serial port must be enabled on the Pi’s GPIO pins. The setup file provided can make these configuration changes to enable to serial interface. This allows your Pi to communicate with the Pi Co-op :
cd pi_co-op sudo python setup_pi_co-op.py install
Finish the configuration by restarting the Raspberry Pi
sudo reboot
Step 2 – Programming The Arduino
When the Pi has rebooted run :
startx
to enter the LXDE desktop.
You can now run the Arduino IDE. This can be done by using the icon under “Programming” within the desktop start menu or typing “arduino” within an LXTerminal command window. When it launches the IDE should look like this :
T here are lots of example scripts within the IDE known as “sketches”. The “hello world” example in the Arduino community is a sketch called “Blink”. Load the “Blink” example using the “File > Examples > 01 Basics > Blink” menu sequence :
The Blink sketch will load and look something like this :
Although the defaults are usually correct, quickly check the board type is set to “Arduino Uno” using the “Tools > Board” menu sequence :
Now check the serial port is set to ttyS0 using the “Tools > Serial Port” menu sequence :
That’s the configuration done. Click the arrow icon to compile the sketch and upload it to the Pi Co-op :
If everything has gone to plane the LED on the Pi Co-op board should start blinking.
Step 3 – Get Hacking!
If you take a look at the Blink example you will see two lines stating :
delay(1000);
This is the delay (in milliseconds) between each LED blink. Change the number to 500 (half a second) and click the arrow icon to compile and upload. The LED should blink faster.
Increase the number to make the LED blink slower.
Next Steps
The Pi Co-op acts like an Arduino Uno so for many projects you can connect up your hardware and find existing Uno sketches to get you started. I plan on doing a few more tutorials demonstrating some typical applications.