Raspberry Pi Adaptor

For E-blocks user to discuss using E-blocks and programming for them.

Moderators: Benj, Mods

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 715 times
Contact:

Raspberry Pi Adaptor

Postby JohnCrow » Tue Oct 02, 2012 6:31 pm

Using The Raspberry Pi & The Matrix EB-080 Interface Board

Part 1

Warning
Points highlighted in red are where you could cause damage to your hardware if care is not taken to ensure connections are correct.

Remember the Raspberry Pi hardware operates at 3.3V, even though the actual power supply required is 5V.
So except for the 5V line to power the board taken from the Matrix expansion board, signals to all the GPIO lines must not exceed 3.3 V, otherwise the processor on the RPi will be destroyed.


Typed Commands
Commands that need to be typed in the terminal window are shown in green.


Introduction:

Unless you have been living in some remote technologically devoid desert island for the last year you cannot have missed all the publicity and hype surrounding the release and massive popularity of the Raspberry Pi.

For those who have not heard about it, the Raspberry Pi is an ARM based computer that runs a version of Linux from an SD card.
What’s so special about it is, it’s only the size of a credit card and it costs about £35.
Only now are they starting to become readily available with a short lead time.
(I waited nearly two months for mine to be delivered.)

Matrix have recently produced a small interface board (EB-080) for the Raspberry Pi
(From here on the Raspberry Pi will be referred to as the RPi).

This has 2 standard female 9 pin D-Connectors, as used in the Matrix E-blocks system.
E-Block hardware can then be interfaced directly to the GPIO port on the RPi.

The board comes with a short ribbon cable that allows the GPIO connector on the RPi to connect to the matching connector on the interface board.

The board can take power from a standard Matrix PSU. Recommended minimum supply current 1A
(Matrix suggest setting it to 7.5V so the 3pin regulator on the EB-080 does not have to drop too much voltage.)
The board uses a bridge rectifier as a protection against reverse polarity. This means the power supply can be wired either way round. This does mean a small drop in voltage to the 7805 regulator but not enough to cause any problems.


The E-block powers the RPi as well, so the micro-usb phone charger should not be connected to the RPi power socket.

The EB-080 has the normal screw terminals for 5V, 3.3V and Gnd.
The 3.3V line is taken from the RPi GPIO.

This article will describe some of the basic interface programs I have written to use the EB-080 with some of the more basic e-blocks.
The RPi will support more advanced protocol such as I2C , SPI and UART, though I just cover the more basic ideas in this tutorial.

This tutorial is based on my own experience with the RPi & EB-080 boards.

I am currently running Wheezy Raspbian 2012-09-18 with GPIO 0.4.0a
This has now made the addition of the following statement in Python Scripts mandatory.

GPIO.setmode(GPIO.BOARD)

Versions for GPIO 0.2 are also included

E-Block.JPG
E-Block.JPG (122.32 KiB) Viewed 10387 times

The EB-080 Raspberry Pi Interface E-Block

There is plenty of information on- line information as to the differences in the versions, and as a general tutorial on python. One major difference between versions that will affect users of these projects is the way the print statement is formatted.

Programming IDE’s:

The RPi does come with basic shells for both Python2 and Python3.
Idle = Python 2
Idle3 = Python 3
These while suitable for simple program development, are very basic and not user friendly for development of large programs, although are perfectly adequate for the programs included with this tutorial.
My personal choice is for the following programs.

Geany (This is freeware).
http://www.geany.org

This is on both my desktop PC and is also the program I use on the RPi.
Note the original Debian release for the RPi included Geany, however from the Wheezy-Raspian release it has to be downloaded and installed from the internet.

Wingware Personal (This is commercial software and has to be purchased)
http://www.wingware.com

A much more advanced programming environment than Geany.
I use this for developing software on the desktop, before moving to the Rpi.
Both a freeware version and a advanced professional version of this program are also available.
Currently cannot be used on the RPi.

The use of these packages is outside the scope of this tutorial. However they both come with comprehensive documentation.

Installing Geany on the Raspberry Pi:

To install the program use the following command.
You need to be connected to the internet to do this.
The sudo statement means you are running with administrator privileges.

sudo apt-get install geany

This is not aimed at being to Python tutorial, though the example programs show below are well documented, so should be easy for a beginner to follow.

If you prefer to use C my personal choice is Code::Blocks, which is another freeware package.
Both Geany and Code::Blocks are released under the GNU licence.
Code::Blocks includes the GNU compiler.
http://www.codeblocks.org/

sudo apt-get install codeblocks

Setting up the GPIO class.

The GPIO class files need to be downloaded from the RPi website and installed.
Without this Python will not know how to control the GPIO lines.

Download the GPIO program from the RPi website
http://code.google.com/p/raspberry-gpio-python/downloads/list

The versions needed depends on if you are using Python 3 or Python 2
Download and extract the files on the PC and copy the folder to the RPi (Or download direct to the RPi)
Using the terminal window, open the folder created above.
Enter the following command to install the package

sudo python3 setup.py install or sudo python setup.py install

Close terminal window

GPIO 0.4.0a is included in the 2012-09-18 release of raspbian and does not need to be installed.

Port Mapping:

The two 9-Pin E-block ports are mapped to the RPi as follows.

Port 1 pins 1 to 8 = RPi GPIO pins 11, 12, 13, 15, 16, 18, 22, 7

Port2 pins 1 to 8 = RPi GPIO pins 24, 5, 3, 23, 21, 19, 8, 10 (Jumper 1)
Port2 pins 1 to 8 = RPi GPIO pins 24, 26, 3, 23, 21, 19, 8, 10 (Jumper 2)

As can be see pin2 on the 9-pin D-Connector can be connected to either pin 5 or 26 on the GPIO depending on how the jumper is set on the EB-080.
The pins are all protected with 220R resistors.
The lines also have the option of installing 3.3 V zener diodes for OVP protection.
However the safest option is to ensure the lines are not connected to anything over 3.3V.


Take care when making any connections to you RPi either directly or via the EB-080, as wrong connections could destroy your RPi.
Always make connections before applying power to either the RPi or the EB-080, and make sure to only use 3.3V.

Ensure the Red strip on the ribbon cable is connected to pin 1 on both the RPi and the EB-080.
If the ports are facing each other as in the photo below then this should be the default connection.
The ribbon cable supplied with the GERT-Board is not suitable for the E-Block as Pin 1 is crossed over.


Programming the GPIO Ports

Output Test Programs:

This is a sample of 4 basic programs that shows a simple way to control the output and drive the
EB-004 LED Board.
The LED board is connected to Port 1 on the interface board.

Note as presented here the programs won’t run on a windows system as they are calling the GPIO hardware on the RPI.

Output System.JPG
Output System.JPG (82.03 KiB) Viewed 10387 times

The Raspberry Pi Connected To The EB-080 & EB-004 LED Board


The following 6 programs are intended as a simple demonstration of the RPi and the E-Block adaptor.
The programs can be run either by opening them in Geany and clicking on the run button.
They can also be run by opening a terminal window, change directory to where the file is saved and typing:

sudo python3 filename.py

Where filename is the name of the program you want to run. Note you need to add the .py extension.

Program 1: Binary Counter.

A simple binary counter on the LEDs. Counts from 0 to 255. Then the cycle starts again.

Program 2: Sequencer.

This turns on and off each LED in sequence with a short gap.
Runs 0 to 7, then the cycle restarts.

Program 3: Knight Rider Light Effect.

Generates the “Knight Rider” effect on the LED’s by running a single LED back and forth across the LED board. Runs 0 to 7 then 7 to 0. Then the cycle restarts.

Program 4: Simple LED Flasher.

Just turns an LED on and off with a short time delay.

Program 5: Keyboard Selected LED

This is to allow a entry of 0 -7 on the RPi keyboard and will turn the corresponding GPIO line on, hold for a set period of time and then turn it off and wait for the next number.
Error checks for both negative entry and values out of range.

Program 6: Random LED Flasher

This is will generate a random number between 0 and 7.
Using that number the corresponding LED will be turned on for a short period, then off for the same length of time. The program will then generate another random number and repeat.
The number of loops is set in the program.

An alternative method of generating a random number is commented out in the program, to use this just un-comment out the line and comment out the current line.

Simple Switch Input.JPG
Simple Switch Input.JPG (58.85 KiB) Viewed 10386 times

Simple Switch Input
These users thanked the author JohnCrow for the post (total 4):
medelec35 (Tue Oct 02, 2012 6:46 pm) • kersing (Tue Oct 02, 2012 6:46 pm) • Enamul (Tue Oct 02, 2012 8:03 pm) • Benj (Wed Oct 03, 2012 9:25 am)
Rating: 21.05%
 
1 in 10 people understand binary, the other one doesn't !

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 715 times
Contact:

Re: Raspberry Pi Adaptor

Postby JohnCrow » Tue Oct 02, 2012 6:39 pm

Using The Raspberry Pi & The Matrix EB-080 Interface Board

Part 2

Input Test Programs:

Full Circuit - Switch.jpg
Full Circuit - Switch.jpg (11.08 KiB) Viewed 10384 times

Simple Switch Circuit Diagram

The following are simple programs to demonstrate the input capabilities of the RPi GPIO Ports.
It is important to ensure the Ports are not set up as OUTPUT when applying a signal to them.
The Matrix board has current limiting resistors, which will help prevent damage should this occur, however it is better to ensure this is not needed.
Circuit was built on the EB016 Protoboard.

Program 7a : Simple Switch - LED

When the switch is closed GPIO 11 goes low (It is normally pulled high by a 10k-ohm resistor to 3.3V)
When this is low (False), GPIO 12 goes low and allows the LED to turn on. I have used a fairly high value resistor on the LED to prevent too much power being drawn from the Rpi. Therefore the LED is fairly dim. Do not use high brightness LEDs for this as they a fairly high current.

Program 7b : Simple Switch - Screen

When the switch is closed GPIO 11 goes low (It is normally pulled high by a 10k-ohm resistor to 3.3V)
Depending on the state of GPIO 11 a message is printed on the screen each time the switch changes state, indicating if it is open or closed.

Program 8a: Matrix Switch Board – LED

This has the Matrix E-Blocks connected to the EB080 as follows.

Port 1 = Switch Board – Connect V+ to 3.3V on EB080 (Uses Bit 0)
Port 2 = LED Board

When the switch is open the RPi GPIO 11 is pulled via the 4k7 resistor to 0V . This is read as False.
When the switch is closed, the RPi GPIO 11 is connected to Vdd (3.3V) this is read as True and the LED on GPIO 24 is turned on.
Other LEDS will be in an indeterminate state due to the fact other channels have not been set.

Program 8b: Matrix Switch Board – Screen

Port 1 = Switch Board – Connect V+ to 3.3V on EB080 (Uses Bit 0)

As in version 8a except instead of toggling the LED, a simple message is shown on the screen.
Switch Open or Switch Closed.
The LED E-Block is not needed for this version.

Program 8c: Matrix Opto-Isolator

This has the Matrix E-Blocks connected to the EB080 as follows.

Port 1 = Opto-Isolator Board – Connect V+ to 3.3V on EB080 (Uses Bit 0)
Set jumper to LOW BYTE
Port 2 = LED Board

When a voltage is placed on Ch1 input terminals on the opto isolator board, this causes a signal to be placed on the GPIO 11 input .
The voltage applied to the opto isolated input does not have to be 3.3V. Though I recommend using about this voltage (2x AAs) . That way if an error is made you are much less likely to cause damage to the RPi.
This causes the LED on GPIO 24 to be turned on in the same way as Program 8a.

Other LEDS will be in an indeterminate state due to the fact other channels have not been set.

Matrix-Switch.JPG
Matrix-Switch.JPG (52.66 KiB) Viewed 10384 times


Matrix Switch & LED Boards

Matrix-Opto.JPG
Matrix-Opto.JPG (48.71 KiB) Viewed 10384 times


Matrix Opto-Isolator & LED Boards

Conclusions

I have put this article together using my experiences with the hardware and learning to program in Python.
The system is capable of much more complex interfacing such as I2C, SPI, UART, however the programming for these is much more complex, and this article is aimed as an introduction.

The included programs have all been tested on my hardware.

Possibly, a follow up article on these protocols will follow once my Python knowledge has expanded a bit.

The Rpi is a wonderful little computer, and with the addition of the Matrix EB080 it has an inexpensive way of connecting to the outside world.
These users thanked the author JohnCrow for the post (total 2):
Benj (Wed Oct 03, 2012 9:25 am) • medelec35 (Fri Jun 05, 2015 10:41 pm)
Rating: 10.53%
 
1 in 10 people understand binary, the other one doesn't !

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 715 times
Contact:

Re: Raspberry Pi Adaptor

Postby JohnCrow » Tue Oct 02, 2012 6:44 pm

Using The Raspberry Pi & The Matrix EB-080 Interface Board

Part 3

This part contains the Python Scripts for the above examples
I have included both scripts for the old GPIO 0.2 and the current GPIO 0.4.
They are mostly in Python 3, but a few Python 2 examples are included as well.

E-Block Python Scripts.rar
(17.88 KiB) Downloaded 422 times
These users thanked the author JohnCrow for the post (total 3):
Steve001 (Tue Oct 02, 2012 6:51 pm) • petesmart (Tue Oct 02, 2012 10:08 pm) • Benj (Wed Oct 03, 2012 9:25 am)
Rating: 15.79%
 
1 in 10 people understand binary, the other one doesn't !

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1086
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 440 times
Been thanked: 492 times
Contact:

Re: Raspberry Pi Adaptor

Postby Steve001 » Tue Oct 02, 2012 6:51 pm

very nice article john :D

Steve
These users thanked the author Steve001 for the post:
JohnCrow (Tue Oct 02, 2012 6:57 pm)
Rating: 5.26%
 
Success always occurs in private and failure in full view.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Raspberry Pi Adaptor

Postby Enamul » Tue Oct 02, 2012 8:08 pm

Nicely organized and huge informative another article from you :)
Your articles are always such nicely oriented that tempt reader to read whole.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 715 times
Contact:

Re: Raspberry Pi Adaptor

Postby JohnCrow » Fri Jun 05, 2015 9:19 pm

Although the RPi is a great little computer, I've not done as much with it as Id have liked recently. I don't have room for a 2nd monitor and having to keep swapping the monitor cable is a pain, plus it means Im not able to use the main PC at the same time. KVM switch was one option I had considered.

Then I found several suppliers were making small LCD displays to plug onto the GPIO connector, great, but it makes it difficult to use it for hardware experiments.

Then I found this lovely display (Adafruit) for a reasonable cost.

Pi-Monitor.jpg
Pi-Monitor.jpg (93.71 KiB) Viewed 8997 times


7" with a 800 x 480 resolution
Uses HDMI connection for video and a uUSB Power Connector.

Very impressed with it.
Only minor downside is it does not have a video scaler so the Pi has to be configured to use that specific resolution.
A 5" version is also available
They can also be obtained as a touch screen as well.
As with all Adafruit stuff, a comprehensive data sheet is available.
These users thanked the author JohnCrow for the post (total 4):
kersing (Fri Jun 05, 2015 10:37 pm) • medelec35 (Fri Jun 05, 2015 10:42 pm) • Steve001 (Sun Jun 07, 2015 4:43 pm) • LeighM (Mon Jun 08, 2015 8:30 am)
Rating: 21.05%
 
1 in 10 people understand binary, the other one doesn't !

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1086
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 440 times
Been thanked: 492 times
Contact:

Re: Raspberry Pi Adaptor

Postby Steve001 » Sun Jun 07, 2015 4:43 pm

very nice , got me thinking of a few uses now :D

Where you get that from john ?


Steve
Success always occurs in private and failure in full view.

User avatar
LeighM
Matrix Staff
Posts: 1912
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 460 times
Been thanked: 646 times
Contact:

Re: Raspberry Pi Adaptor

Postby LeighM » Mon Jun 08, 2015 8:32 am

Hi John,
That looks good.
btw, Did you know that another option with the Pi (as with any Linux) is to get into the desktop remotely. That is, if you connect the RPi to your home network router.
Just install xrdp on the RPi (sudo apt-get install xrdp), then you can use (Microsoft) Remote Desktop client on your PC to view the RPi desktop. (Use ifconfig on the RPi to get its IP address)
Regards,
Leigh
These users thanked the author LeighM for the post:
medelec35 (Mon Jun 08, 2015 8:37 am)
Rating: 5.26%
 

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 715 times
Contact:

Re: Raspberry Pi Adaptor

Postby JohnCrow » Mon Jun 08, 2015 3:11 pm

Hi Steve

It came from skpang.com

Hi Leigh

Thanks for that, yes im using x11vnc on mine and vnc on the desktop (and on the IPAD too)
1 in 10 people understand binary, the other one doesn't !

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1086
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 440 times
Been thanked: 492 times
Contact:

Re: Raspberry Pi Adaptor

Postby Steve001 » Mon Jun 08, 2015 9:13 pm

cheers for that john

steve
Success always occurs in private and failure in full view.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 715 times
Contact:

Re: Raspberry Pi Adaptor

Postby JohnCrow » Fri Jun 12, 2015 5:17 pm

Hi

Are you planning a Rpi case for the new style RPi

Just put one together for my old type pi, very nice case, and very high quality (laser cutting I assume) hardest part about assembly is getting the protective film of the parts.

Couple of personal observations

1) I would have preferred to have been able to have the option of being able to plug the USB power lead in rather than power it from the E-Block.

2) Its not possible to connect the camera to the Pi in the case. Not a problem for me as my camera is on the more powerful Pi 2. Will use this one for hardware experiments.
These users thanked the author JohnCrow for the post:
Benj (Mon Jun 15, 2015 3:42 pm)
Rating: 5.26%
 
1 in 10 people understand binary, the other one doesn't !