Skip navigation
2013

I have a Raspberry Pi Gertboad (21 Oct 2012 version) purchased fully assembly but missing the leds? I have no soldering tool, can I get another one? I can't test the leds and the push buttons if I miss the leds.

I purchased it this past summer but I did not get to it due to my work and school schedule. Anyone had this problem?

This post is intended to demonstrate compatibility of the chipKIT Pi with certain existing Arduino shields. In the second part of this post, we will also demonstrate how to communicate with the chipKIT Pi over a simple I/O line on the Raspberry Pi, from a terminal window, to control the Arduino shield connected to the chipKIT Pi.

 

Hardware Used:

  • Raspberry Pi
  • chipKIT Pi Raspberry Pi Add-on Board
  • Arduino Motor Control Shield

 

Procedure:

Let’s begin by simply controlling a common Arduino shield.

 

NOTE: Always check the electrical characteristics of any shield that will be connected to the chipKIT Pi. As with the Raspberry Pi, this is a 3.3V system. Therefore, if a shield outputs voltages greater than 3.3V there is a possibility that you could damage the chipKIT Pi or the Raspberry Pi. 

 

Connect the Arduino Motor Control Shield as shown:


pictureone.png

picturetwo.png

  1. 1. Start a new sketch in MPIDE
  2. 2. We will be using Brian Schmalz’s SoftPWMServo library for this application. This is a very flexible library that will enable a PWM (square wave) output on any pin we like. This library comes already included as a core library with the MPIDE. Therefore, to use, simply add the header file to the library at the top of your sketch as follows:

    #include <SoftPWMServo.h>

  3. 3. The remainder of the sketch follows set up as per the Arduino Motor Control Shield specifications. I’ve added comments to explain each line of code.

//Include the SoftPWMServo Library

#include <SoftPWMServo.h>

 

void setup() {

  //set up channel B on the Arduino Motor Control Shield

 

  pinMode(13, OUTPUT); //Pin 13 controls direction

  pinMode(8, OUTPUT);  //Pin 8 controls the brake

 

 

}

 

void loop() {

 

  //Turn the motor

  // Firs we disengage the brake for Channel B

  digitalWrite(8,LOW);

 

  //Depending on how your motor leads are connected to the Arduino

  //motor B header, the direction could be clockwise or counter clockwise

  //So let's just start by calling this direct 1 and drive pin 13 HIGH

  digitalWrite(13,HIGH);

 

  //We need to send a PWM to the Arduino MC shield to start the motor

  //turning. We also define a duty cycle that will set the motor speed.

  //The higher the duty cycle, the faster the motor will turn. Duty cycle

  //is set between 0 and 255.

  //So we send the PWM to pin 11 according to the Arduino MC specs at say

  // a duty cycle of 100

  SoftPWMServoPWMWrite(11, 100);

 

  //Let's run the motor for about 5 seconds

  delay(5000);

 

  //Now lets brake the motor

  digitalWrite(8,HIGH);

 

  //Give the motor a chance to settle

  delay(500);

 

  //change directions

  digitalWrite(13,LOW);

 

  //and run the motor for about 5seconds in the other direction

  delay(5000);

 

  //Again, we brake the motor

  digitalWrite(8,HIGH);

 

  //give the motor a chance to settle

  delay(500);

 

  //and repeat

 

}





So, this is nothing really special and can be done on any chipKIT Board. However, we can make something pretty interesting by introducing some Python-based communication from the Raspberry Pi to the PIC32 MCU on the chipKIT Pi.

 

In this example, a General Purpose Input/output line on the Raspberry Pi Expansion Connector will be used send a HIGH or LOW logic level from the Pi to the chipKIT Pi to turn the motor on or off.

 

Hardware Setup:

 

Simply connect a jumper wire from the J1 RPi-Connect header in the upper left corner of the chipKIT Pi. Here I’ve connected the third pin down on the bottom side of the header which is GPIO4 as per the diagram below.

 

picturethree.png

We will connect this pin to an available input on the chipKIT Pi. Referring to the Arduino Motor Control Shield Schematic, we note that pin 4 is available. This conveniently has the same number as our GPIO on the Raspberry.

 

This connection is illustrated below. (Note that the Arduino Motor Control Shield is not shown to make it easier to see this connection.)

picturefour.png

 

Software Setup

 

In this application example, when the GPIO4 line is driven HIGH (3.3V) by the Raspberry Pi, the chipKIT Pi will read this and turn on the motor. When the GPIO4 line is driven LOW (0V) the chipKIT Pi will turn off the motor.

 

Let’s setup the chipKIT Pi sketch first.

 

The sketch is setup as it was in the previous example only adding Digital Pin 4 as an input that will receive the signal from the Raspberry Pi.

 

In the loop(), the code first checks digital pin 4, if it reads a LOW/False/0V signal it calls the function allStop() which simply applies the brake signal on pin 8. If it reads a HIGH/True/5V signal it will call the turn() function that disengages the brake for 5 seconds, then reapplies the brake.  The full sketch is below:

 

//Include the SoftPWMServo Library

#include <SoftPWMServo.h>

 

int  Pi_GPIO = 0;

 

void setup() {

  //set up channel B on the Arduino Motor Control Shield

 

  pinMode(13, OUTPUT); //Pin 13 controls direction

  pinMode(8, OUTPUT);  //Pin 8 controls the brake

 

  pinMode(4, INPUT); //Input line from Raspberry PI GPIO

 

 

}

 

void loop() {

 

  //We need to send a PWM to the Arduino MC shield to start the motor

  //turning. We also define a duty cycle that will set the motor speed.

  //The higher the duty cycle, the faster the motor will turn. Duty cycle

  //is set between 0 and 255.

  //So we send the PWM to pin 11 according to the Arduino MC specs at say

  // a duty cycle of 100

  SoftPWMServoPWMWrite(11, 100);

 

 

  //Read the inputs from the Raspberry Pi

  Pi_GPIO = digitalRead(4);

 

 

  //Generate motor output based on inputs from the Pi

 

  if (Pi_GPIO == 0){

    allStop();

  } 

 

   else if (Pi_GPIO == 1){

    turn();

  }

 

 

}

 

void turn(){

 

 

    //Set for directionA

   

  digitalWrite(13,HIGH);

   // First we disengage the brake for Channel B

  

  

  digitalWrite(8,LOW);

 

 

 

 

  //Let's run the motor for about 5 seconds

  delay(5000);

 

  //brake the motor

  digitalWrite(8,HIGH);

 

 

  //give the motor a chance to settle

  delay(500);

 

}

 

 

void allStop(){

 

  //brake the motor

  digitalWrite(8,HIGH);

 

  //give the motor a chance to settle

  delay(500);

}

 

 

Place the chipKIT Pi into bootloader mode and download the sketch.

 

In order to communicate with chipKIT Pi, we will need to download the GPIO package for Python as follows:

 

Installing GPIO package for Python:

  1. 1. Open a terminal window and download the latest version of the GPIO Package for Raspberry Pi. At the time of this post, the latest version was RPi.GPIO-0.5.3a:

    sudo apt-get update
    sudo apt-get -y install python-rpi.gpio


  2. 2. Next step, open python within the terminal window (note Python 3 is used here):
    $ sudo python



  1. 3. Instead of typing the full RPi.GPIO name every time, we will set it up so that using just GPIO does the same thing:

    >>> import RPi.GPIO as GPIO



  1. 4. Next, we need to define the type of numbering we will use
    GPIO.setmode(GPIO.BCM) -- Broadcom GPIO numbering
    or
    GPIO.setmode(GPIO.BOARD) -- board pin numbering

    Here I used BCM. If you need more of an explanation on this, there are tons of resources on the web to explain this.

    >>> GPIO.setmode(GPIO.BCM)


  2. 5. Now we need to let the Raspberry Pi know that we will be using GPIO4 as an output:

    >>> GPIO.setup(4, GPIO.OUT)


  3. 6. Finally, to send a HIGH/True/3.3V over the selected pin:

    >>> GPIO.output(4, True)

 

Note that if all went as planned the motor connected should now start turning.

 

To send a LOW/False/0V over the selected pin to turn off the motor:

 

>>> GPIO.output(11, False)

 

The complete terminal code is show below:

 


pi@raspberrypi ~ $ sudo python3

Python 3.2.3 (default, Mar  1 2013, 11:53:50)

[GCC 4.6.3] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import RPi.GPIO as GPIO

>>> GPIO.setmode(GPIO.BCM)

>>> GPIO.setup(4, GPIO.OUT)

>>> GPIO.output(4, False)

>>> GPIO.output(4, True)

>>> GPIO.output(4, False)

Want to build this project?
View Parts


Update (7/15/14):  Check out my new Goldie skateboard! Part of my new line of Goldie Fishwater products?

Goldie bottom .jpgGoldie top.jpg


Disclaimer: I’m an engineer, not a pro film maker. Be advised.

Disclaimer: I’m an engineer, not a pro film maker. Be advised.


"pro-tip" - I recommend watching all the times in bold below...

Video time map.. see what you want:

00:00 The story of Goldie, opening animation

03:25 Video start, my opening thoughts

05:47 Boardganizer overview

10:56 I show the components of the system

12:24 The fishfeeder

13:05 The limit switches

14:00 AC power

14:10 The moving platform

14:40 Powering the system accidentally...

15:05 Goldie gets stuck in the circuit!

15:30 Showing the moving platform and fishfeeder working, relay too

16:37 The web interface, how this system is controlled. Early test of all components.

20:09 Alienspec Pi Camera cable extension, 2 meters long!

21:00 Setup of the moving platform

22:06 Horizontal test of the system on the actual tank!

24:22 Change from horizontal to vertical

24:48 Vertical real world test!

27:14 Feeding Goldie!!! The reason for the system!!!

28:00 Temp sensor, moot point.

28:21 Fishfeeder and AC portion working.

30:30 Thoughts on the system, more Goldie shots.

31:35 My final thought.

33:00 Goodbye Goldie, closing animation

:

 

happy Right.jpg


I never thought I could love a fish.

 

But I do. Goldie Fishwater is a survivor – she’s so strong. Truly, she is an inspiration to me… to us all…


I went on a trip recently, and found myself worrying about Goldie’s well being more often than I ever imagined I would. I had a friend stop by my place to check on her. Unfortunately, my friend didn’t know what to look for, and my automatic fish feeder broke during my trip!

The tank was action packed with food. To no surprise, Goldie ended up getting over fed. In fact, she doubled in size! I returned to another traumatic, near death event for Goldie. I hopped to save her. While changing the filters and tank water twice, I thought I could not let this happen again. I want to see Goldie in real time, and feed her myself. There is no love in an automatic fish feeder.


Here were my requirements of

  1. I want to see Goldie in real time, at all times.
  2. Move the camera stream around the tank to where Goldie might be
  3. Cut the power to the tank’s filters and air bubbler
  4. Feed Goldie at manually
  5. Sense the tank temperature
  6. Above all, do all this through a network - and ultimately via the Internet

 

I knew The Raspberry Pi and Pi camera would be perfect for #1 and #6. An Arduino Uno would be a good choice for #2 through #5. I came up with this block diagram.

block2.jpg

 

Curious about all of Goldie’s hardships?

- Attacked twice by other fish. All fins and tail ripped off

- Ammonia burns on her wounds

- Swim bladder damage from being attacked, then infection. She couldn’t swim!

- Fungal infection

- Overfeeding and contaminated water

 

 

Project by sections

- Motor control

I chose two small Nema 17 mount stepper motors from Adafruit for my driver components. Of course, I used the Arduino Motor Shield to make short work of the motor controls. This was fairly straight forward type of connection. Coils A & B go to their designated spots on the motor shield, see the datasheet. Each motor had a different task. One needs to rotate 360 degree to dump fish food from the container. However, the other needs to allow for movement in both directions.

Limit switches also had to be incorporated to keep the motor from traveling too far in either direction. I used some Omron plunger micro-switches. I attached rare-earth magnets to each, so I can adjust the movement range as needed.

 

- The moving platform

I originally wanted the create a leadscrew driven platform for the camera movement. However, I opted for a surplus belt driven motion platform, mainly for price. The difference being $60 versus $15. This platform also gave me more travel that I had originally planned. This is great for viewing the entire length of the tank.


- Temp sensor

I used a waterproof DS18B20 Digital temperature sensor, for obvious reasons. Although Goldie, and her former roommate, are fresh water fish where room temperatures are ok, too cold or hot could be an issue. My building has a tendency to lose the air conditioning/heat exactly when inconvenient. This would alert me to any particular issue. IE: Direct sunlight overheating the water.


- Video

I needed a video stream to watch Goldie, I had a choice between VLC and Gstreamer. Although Gstreamer is a common choice for Raspberry Pi, I went with VLC for the ease of use. Mostly due to the out of the gate support Windows. Gstreamer may have needed some further development on my part. However, going with VLC was not a perfect solution. VLC suffered from a buffered delay that seemed to build over time. I wanted the highest resolution stream of course, but VLC seemed to really bog down over 640x480 pixels at 15 frames per second. So, I stuck with those settings.

Though, I will admit, I would like to do better in this area.


- Relay (AC power)

I wanted to use an off the shelf relay actuated AC outlet, the Powerswitch tail 2. However, it was out of stock. I took an off the shelf AC power strip and cut the black wire (the hot), internally, and sent two leads to the relay board. Easy, but, not as safe as I would have liked.


- Goldie the Diva

‘Nuff said.

 

The difficulties

- Mounting the system and long camera cable

I had intended to mount the entire system on the moving platform, since the Pi Camera ribbon cable was so short (6 inches or 15.54 centimeters). But, as I added features and cabling, it became too bulky and heavy. So, lengthening the camera cable was the only way. I could have adapted an old IDE cable from a derelict desktop in the mountain of surplus I have. However, I found several companies making solutions for my problem already, and a bit more elegant. The one I chose was from AlienSpec, a 1 meter long ribbon cable, just like the oem one… but longer. They were nice enough to rush ship me one right away. They even sent a 2 meter long one! This was a more logical solution.

- Motor control, switch from another dev board

There is no documentation say which wires on the stepper motors are part of what coil. So, measuring the resistance across the wires was the only way. Wires that are part of the same coil will show some sort of small resistance, while the others look like open circuits.

When I started out on my endeavor, I used a Chipkit Pi. However, I found it easier to adapt the motor shield to the Arduino Uno.

- Fish feeder

I wanted a better solution, but I used the original feeder drum from the malfunctioning feeder that made Goldie huge. It is a simple trap door that opens briefly when rotated completely around. I machined a sleeve to fir over the motor shaft and into the feeder’s mount hole. Simple enough, but it isn’t perfect. The drum need to be indexed a certain way, but the stepper motor might slip. Moving the motor back induces back current… not good for the stepper driver shield!

 

- Internet connectivity

I did not work on port forwarding, and access to the public Internet. That was my intention, but a few things turned me away. Opening up my home network, not that big of a deal, but more importantly… home safety. I was worried that my system, especially the AC portion, would start a fire. More trials will be needed before I go this route.

- Fire

An ever present worry…

 

Pics and system

 

Schematic and Design

schematic.JPG

 

Code

 

 

Product Name*DescriptionSupplier
Raspberry Pi Model BA credit card-sized board with a Broadcom BCM2835 System-On Chip running Linux.Raspberry-Pi
Buy NowBuy Now
Arduino UnoThe Arduino Uno is a microcontroller board based on the ATmega328.Arduino
Buy NowBuy Now
Pre Programmed, MicroSD, 8GB, Raspberry PiRaspberry Pi 8GB SD Card pre-loaded with NOOBS—a collection of 6 operating systems.Raspberry-Pi
Buy NowBuy Now
Breadboard, Solderless, 400 Tie PointsBreadboard, Solderless, 400 Tie PointsTwin Industries
Buy NowBuy Now
Budget Pack, Raspberry PiBudget Pack for Raspberry Pi (Mostly unused, only for parts)Adafruit Industries
Buy NowBuy Now
BUD BoardganizerMulti-development Board Enclosure KitBUD Industries
Buy NowBuy Now
Raspberry Pi Camera ModuleThe Raspberry Pi Camera Module is a custom designed add-on for Raspberry Pi.Raspberry-Pi
Buy NowBuy Now
Omron Electronic Components - D2HW-BL201M - Micro SwitchSnap-action switch for reliable ON/OFF actionOmron Electronic Components
Buy NowBuy Now

*Products and resources listed are listed to help members build their own Pi Projects. They are suggestions and listed for educational purposes. For substitutions of any parts, please post a question asking the original author.

 

 


Project Goldie - breakdownQUANTITYUnit PriceVENDORVendor Part#PRICE
Raspberry Pi Model B1$35.00element1443W5302$35.00
Arduino Uno1$29.95element1478T1601$29.95
PRE PROGRAMMED, MICROSD, 8GB, RASPBERRY PI1$17.99element1497W1422$17.99
BREADBOARD, SOLDERLESS, 400 TIE POINTS1$7.35element1456T0249$7.35
BUDGET PACK, RASPBERRY PI (Mostly unused, only for parts)1$49.95element1444W3511$49.95
BUD Boardganizer2$16.32element1488W3963$32.64
Raspberry Pi Camera Module1$25element1469W0689$25.00
OMRON ELECTRONIC COMPONENTS - D2HW-BL201M - MICRO SWITCH2$6.55element1425C4430$13.10
Raspberry Pi Camera Cable 1 meter1$20.86Alienspec313-100$20.86
Fish Tank feeding wheel1$16.00AmazonNA$16.00
Small Reduction Stepper Motor - 5VDC 512 Step2$14.00Adafruit324$16.00
Waterproof DS18B20 Digital temperature sensor + extras1$9.95Adafruit381$9.95
4-channel I2C-safe Bi-directional Logic Level Converter1$3.95Adafruit757$3.95
12V 5A switching power supply1$24.95Adafruit352$24.95
Zitrades (SaneSmart) 5V 8 Channel Relay Module for Arduino DSP AVR PIC ARM1$14.25AmazonNA$14.25
Palm Touchpad 5V 2A microUSB power supply1$5.00AmazonNA$5.00
Linear Motion Slide Actuator Nema 17 mount1$15.00EbayNA$15.00
Power strip1$3.95Home DepotNA$3.95
3M Dual-Lock strips1$14.95TargetNA$14.95
Rare earth magnets, wire, wire nuts, solder,
Total$355.84


 

Other uses of the system

- Any pet control, watch the dog/cat/hamster/spider/ whatever. Feed them too.

- Any system observation and control. Watch your front porch for packages with VLC.

 

If I had more time and money

- Full internet control. This is going to happen, but not yet.

- Better AC control. I want to try the Powerswitch Tail device. I was also considering actuating a wireless control system too.

- More sensors. PH level, ammonia, Nitrate levels are a concern too.

- Better feeding system. This is going to happen too, but need to come up with a better way. I am considering a paddle wheel option.

- Full observation of tank. I want to create a 3D style observation arm. Think a robotic arm with a camera at the end.

 

Oddities and observations

- Powering the dev boards by turning the stepper motors. Turning the stepper motors would create a current that would flood every board with power. When adjusting the stepper motors I would end up activating the relays. What is a generator? An electric motor driven externally.


Cabe

http://twitter.com/Cabe_Atwell


(all cartoons, by Cabe Atwell)

Filter Blog

By date: By tag: