Raspberry Pi - Picaxe Serial Interfacing

mjf

New Member
Hi all,

I've spent the last couple of days trying to get a R.Pi and a Picaxe to talk to each other using the GPIO serial port (rather than plug in the AXE027 USB.) I thought I'd post what I've learnt:

I have been using the UART pins on the GPIO header, These are header pins 8 (Tx) and 10 (Rx). In addition you'll also need 0v from header pin 6.


Interfacing circuit:

1. Connect the ground (0v) of the RPi and the Picaxe together

2. Level conversion - The RPI serial port uses 3.3v so we must use some simple level shifting circuits to interface this with the (in my case 5v) Picaxe supply.

2.a) Picaxe Tx -> RPi Rx . This is a simple 5v->3.3v conversion and can be done using a simple voltage divider.

I used two 100KOhms.
On this diagram - connect Vin to your picaxe serial output pin, and Vout to the RPi Rx GPIO pin

2.b) Rpi Tx -> Picaxe Rx . We want to step up 3.3v to 5v. This requires a transistor circuit known as the voltage follower.

The supply rails are connected to 5v and 0v respectively (the picaxe power supply).
The Tx GPIO pin from the RPi is connected to the transistor base (good practice says you should have a high value [100k] resistor between the Tx pin and the base, though it will work without)
The load resistor should be around 10Kohms, and the output connected to your serial input pin on the picaxe.

3. The RPI serial port uses the "idle high" configuration* so when setting the baud rate on the serout or serin command be sure to use the TRUE flag (e.g. T9600_8)


This configuration should allow you to send and receive data via the RPi's serial port. To send data you will need to open a serial console, I use minicom, on the RPI. The UART port is /dev/ttyAMA0 (at least on the Debian install).
Remember you will have to set the baud rate and the protocol (8 bits, no parity, one stop bit)

This works well for me using a 14m2. My plan is to write code which will allow reading and writing to the picaxe I/O pins via the serial link. Effectively turning the Picaxe into an IO extender, though potentially much more if some of the more exciting picaxe functions are implemented. Using the infra red capability it would be relatively easy to build a remote control for your RPi.
 

boriz

Senior Member
Thanks for that. RPi is definitely something I'll be getting into eventually. Just waiting for the 'early adopter syndrome' to fade a bit. :)
 

Jakob2803

Senior Member
mjf, is the Rasberry Pi good? I was thinking of getting one. How powerful is it, can it run a browser without lagging? :)
EDIT: On linux. :)
 

MartinM57

Moderator
Welcome to the forum :)

2.b) Rpi Tx -> Picaxe Rx . We want to step up 3.3v to 5v. This requires a transistor circuit known as the voltage follower.
I'm not sure a voltage follower (aka emitter follower) is appropriate here - the output voltage follows the input voltage, but is actually about 0.6v (a diode drop across base and emitter) less - so it reduces the Pi output voltage rather than stepping it up. However, depending on what PICAXE input you are connecting to, it may well work just fine. There are many ways of converting 3.3v logic to 5.5 logic from simple "dirty diodes" to specific converter chips - some techniques will invert the signal on the way, so that needs to be taken into account - there's a few ideas at http://www.newark.com/pdfs/techarticles/microchip/3_3vto5vAnalogTipsnTricksBrchr.pdf
 

mjf

New Member
I'm using it 'headless' for running network services (and picaxe tinkering!) so I haven't tried used it for web browsing at all.
Its graphics card is very powerful and a friend of mine is using it very successfully as a media centre (just plugged straight into a projector and streams over network).

If you're looking for just a quick, easy, web browsing machine I think you'll have to wait 6 months while the open source community write some easy to use software for it - at the moment you have to get very friendly with terminal commands to get stuff done.

I'm just going to use it as a powerful micro controller with USB and networking. My long term goal being: RPi+picaxe+2 motors+webcam+wireless = cheap wireless robot.

Matt


edit:

Martin, you are correct - I had lazily hacked that together. It does still work, but completely fails to step up to 5v!
A more useful circuit (one that actually steps up to 5v!) would be:

A you say, this would also invert the signal so the serin baud setting would have to be changed accordingly.
 

g6ejd

Senior Member
The RPI is OK, that's about as good as it gets for me. For I/O work and general device interfacing I would not use the RPi. I run Debian and the browser speed is 'slow', overall for none graphics work it's slow, the CPU generally runs at near 100%. As yet there is no PDF or java or Flash support in gthe browser, maybe soon. The Debian is a bit rough, OK is about all I'd say for it. SOme minor mods to the boot process and updates can make a huge difference. SD Card support is problematic, but later buidls have resolved most of that. Netwrok is stable IMO and works well. Mine runs at 100Mb.

The primary benefit for me is it's a self-container unit, so drives a monitor.

Arduino development environment is reputed to be in the progress of being ported to the RPi, so that will make a huge difference; in principle it should be easy, the largest task is the compiler proper, but I have no doubt that will be done given the resources behind it all.

So-far I/O is via PYTHON for me.

If I were to interface between a RPi and PICAXE I'd just use series R for RPI>PICAXE (5v to 3.3V) and direct connection for PICAXE>RPi (3.3V to 5V).
 

hippy

Technical Support
Staff member
If I were to interface between a RPi and PICAXE I'd just use series R for RPI>PICAXE (5v to 3.3V) and direct connection for PICAXE>RPi (3.3V to 5V).
That should work but no one has so far revealed full I/O specifications such as what the maximum injection current is so resistor value required has to be guess work and in the absence of knowing if there are internal ESD clamping diodes it's probably best to add external diode clamps.

Power the PICAXE off 3.3V and problems are minimised. Some low value resistors in series would be recommended but not essential. Power can be taken from the R-Pi board but there's a max limit of about 50mA.

An alternative would be to connect an AXE027 to a USB port and use the standard 10K/22K download interface,
 

dr_robert

New Member
Hi all,

I've spent the last couple of days trying to get a R.Pi and a Picaxe to talk to each other using the GPIO serial port (rather than plug in the AXE027 USB.) I thought I'd post what I've learnt:

I have been using the UART pins on the GPIO header, These are header pins 8 (Tx) and 10 (Rx). In addition you'll also need 0v from header pin 6.


Interfacing circuit:

1. Connect the ground (0v) of the RPi and the Picaxe together

2. Level conversion - The RPI serial port uses 3.3v so we must use some simple level shifting circuits to interface this with the (in my case 5v) Picaxe supply.

2.a) Picaxe Tx -> RPi Rx . This is a simple 5v->3.3v conversion and can be done using a simple voltage divider.

I used two 100KOhms.
On this diagram - connect Vin to your picaxe serial output pin, and Vout to the RPi Rx GPIO pin

2.b) Rpi Tx -> Picaxe Rx . We want to step up 3.3v to 5v. This requires a transistor circuit known as the voltage follower.

The supply rails are connected to 5v and 0v respectively (the picaxe power supply).
The Tx GPIO pin from the RPi is connected to the transistor base (good practice says you should have a high value [100k] resistor between the Tx pin and the base, though it will work without)
The load resistor should be around 10Kohms, and the output connected to your serial input pin on the picaxe.

3. The RPI serial port uses the "idle high" configuration* so when setting the baud rate on the serout or serin command be sure to use the TRUE flag (e.g. T9600_8)


This configuration should allow you to send and receive data via the RPi's serial port. To send data you will need to open a serial console, I use minicom, on the RPI. The UART port is /dev/ttyAMA0 (at least on the Debian install).
Remember you will have to set the baud rate and the protocol (8 bits, no parity, one stop bit)

This works well for me using a 14m2. My plan is to write code which will allow reading and writing to the picaxe I/O pins via the serial link. Effectively turning the Picaxe into an IO extender, though potentially much more if some of the more exciting picaxe functions are implemented. Using the infra red capability it would be relatively easy to build a remote control for your RPi.

Thanks for this, I think it has got me most of the way there...but not quite all the way! I seem to get data from my picaxe (8M2), but it's gobbledygook. I've tried every combination of baud rates to see if that helped, but no joy. Are you able to say exactly what your set up is please? I am using minicom 2400 baud, no parity, 8 data bits, 1 stop bit and my picaxe code is simply:

main:
serout 0,T2400_4,("Hello")
pause 2000
goto main

Thanks

Rob
 

g6ejd

Senior Member
Assuming you have set the RPi receiver up correctly, 2400 baud, 8N1 then I would quickly try:

serout 0,N2400_4,("Hello")

To invert the data. What speed are you running the PICAXE at, I'm wondering why you are using 2400_4 rather just 2400?
 
Top