The BB has 4 TTL serial ports available, and this how-to will show you how to use one to talk to an Arduino. I'm going to show this by using a minimal Arduino on a breadboard, but you can do this with a normal Arduino as well, just use an external power adapter and don't plug in the USB. The "gotcha" to this is that the BB's ports run at 3.3VDC and the Arduino runs at 5VDC. We'll solve that using a logic level shifter.
Things you'll need:
- Breadboard and some jumper wires
- a BeagleBone (any revision including black should work the same)
- an Ardunio
- a Logic level shifter that supports 5v-3.3v and bi-directional on the TX line. I'm using Sparkfun's
- you know how to program and do some basic wiring with an Ardunio
- you know how to install python packages and run scripts on your BeagleBone
Step 1: Program the Ardunio
the basic logic is this:
- in setup(), turn on LED for 2 seconds and wait, this gives us some warning in case were not ready for serial data yet.
- write an "A" to the serial port
- turn on LED for .2 second
- read serial port and if it reads an "A" , turn on LED for 1 second.
program the Arduino in whatever method you are accustomed to. when programmed and powered on, the led should blink about 5 times a second.
Step 2: Program the BeagleBone
I'm just using the PyBBIO serial echo example as is, it simply takes whatever it receives on Serial2, prints it, and sends it back. This should give our Arduino program back the "A" it sends, which will cause it to then turn the LED on for 1 second. If there's any bad wiring or external noise corrupting the signal, the Arduino wont' see the "A".
You can also write your own serial echo script in whatever language you want.
Step 3: Wire It All Up!
I've included a Fritzing showing what this might look like with a normal Arduino.
Start with everything powered off, just in case.
First, lets put power to the level shifter:
- Connect both GND pins to the ground,
- Connect the HV pin to the bread board 5V rail
- the LV pin will get connected to the BB later
Next, connect the BeagleBone:
- P9 pin 1 (GND) to the breadboard ground rail
- P9 pin 3 (3.3v) to the level shifter LV pin
- P9 pin 21 (Serial2 TX) to one of the level shifters low side TX pin (TXI)
- P9 pin 22 (Serial2 RX) to one of the level shifters low side RX pin (RXO)
- in the photo, ignore the wire going to the Arduno's reset pin, that's for a later Instructible.
Finally, connect the Ardunio. we're making what's known as a "null modem cable" in PC land. The BB's TX data needs to end up on the Arduino's RX pin:
- D0 (RX) to level shifters high side TX pin (TXO).
- D1 (TX) to level shifters high side RX pin (RXI)
- LED on pin 13 as you normally would
NOTE: If you have a 3.3V Arduino, you can connect the BB and Ardunio together directly, without the level shifter.
NOTE2: I've found communication to be more reliable if the RX and TX wires are twisted around each other like this. The twisting causes EMF interference to be reduced.
Power up the Arduino and the LED should start blinking as before.
Boot up the BB and move to the next step
Step 4: Make It So
You should see the "A" received, and the Arduino should change to a short-blink--long-blink pattern. If it doesn't, you have something off in the wiring. Make sure the RX's and TX's are right, if you get the backwards it won't hurt anything, just don't connect the Ardunio's 5V and BeagleBone bone directly together anywhere because it will damage the BeagleBone. Only the GND can be connected directly in this demonstration.
make a framework to get your data back and forth! If you're working from scratch, the Ardunio SerCommand library is very easy to use.
Check out my follow up Instructible that will make use of that reset wire to program the Ardunio from the BeageBone! no more pulling chips or connecting FTDI in awkward installations.