Details- Adding Expansion Boards

Details - Adding Expansion Boards

We begin with some correspondence with “Andrew” of AB Electronics, a supplier of printed circuit boards based in the UK. I had bought a Rasberry Pi 3 B-plus from Amazon, and two IO Pi Plus expansion boards from AB Electronics. …time to hit the internet and find out what to do next. As it turned out, AB Electronics’ website was an excellent place to start. I asked for help on their Community Forum, and Andrew from their company answered almost immediately. Here’s a series of postings.

08/02/2020 Posted by: el Ducko Location: Texas, USA

Having just bought and stacked a couple of IO Pi Plus expansion cards, I'm ready to hook 'em into my model railroad program and drive some relays. I'm rooting around, trying to find some C code that will show me how to do that. I've found a nice explanation in multiple buttons lighting multiple leds but it's written in python and has code such as

from ABE_helpers import ABEHelpersfrom ABE_IoPi import IoPi i2c_helper = ABEHelpers()i2c_bus = i2c_helper.get_smbus() # create the two busesbus1 = IoPi(i2c_bus, 0x20)bus2 = IoPi(i2c_bus, 0x21) # set bus 1 to be inputsbus1.set_port_direction(0, 0xFF)bus1.set_port_direction(1, 0xFF) #....etc

which I can't use in C. I haven't had a look at the ABE_helpers file(s) to see if I can borrow" some code to translate into C. A much better solution would be to find a similar example in C code which can point me in the direction that I need to go.

Can anyone help with a nice, clear example, please? I imagine that it will involve downloading from abelectronicsuk / ABElectronics_C_Libraries

Computer geek since 1964. Upgraded to FORTRAN66 back in the day. Downhill ever since.

09/02/2020 Posted by: andrew Location: United Kingdom

We have a C library for the IO Pi which includes some demos for writing and reading to the IO Pi bus. You can find them on our github repository at https://github.com/abelectronicsuk/ABElectronics_C_Libraries/tree/master/IOPi

One thing to be aware of when driving relays with the IO Pi Plus is each chip can only supply 20mA per channel and a total of 125mA per bus so you will probably need to use a transistor or darlington array to drive the relay coils.

We have a design for a 16 channel relay board that works with the IO Pi Plus which we have made available for anyone to download and build themselves, you can find it at https://www.abelectronics.co.uk/kb/article/1060/relay-board-for-the-io-pi-plus-2-1 We do not sell the relay board ourselves at the moment but you can use the supplied gerber files order PCBs from a supplier like iTead or JLC PCB.

AB Electronics UK Tech Support

09/02/2020 Posted by: el Ducko Location: Texas, USA

Perfect, Andrew- - exactly what I needed. Thanks for the speedy response, especially on a Sunday. ...time to "rattle some iron," as we used to say in the petrochemical business.

...wish I had known about that relay board when I speced out my hardware. I wound up stacking 8-relay boards and fumbling with building custom 20-wire ribbon cables from the IO Pi Plus cards to connect to 1x10 pin setups on the relay cards. I used pairs of 2x20 ocket plugs, plugging the extra row on each with a hot glue gun. Necessity is the mother of... Well, we won't go there. Thanks for the great help. I'll report back, hopefully soon.

Computer geek since 1964. Upgraded to FORTRAN66 back in the day. Downhill ever since.

09/02/2020 Posted by: el Ducko Location: Texas, USA

So far, so good. I downloaded your https://github.com/abelectronicsuk/ABElectronics_C_Libraries/tree/master/IOPi material, copied test.c from the IOPi directory, "apt-get" got and installed i2c-tools and libi2c-tools, and edited the top of my test.c copy to

#include "home/pi/ABElectronics_C_Libraries/IOPi/ABE_IoPi.h"#include "home/pi/ABElectronics_C_Libraries/I2CSwitch/ABE_I2CSwitch.h"

I modified my$PATH to look in /home/pi/ABElectronics_C_Libraries/IOPi and /home/pi/ABElectronics_C_Libraries/I2CSwitch. I tried building the code with

gcc -Wall -o "%e" "%f" -lwiringPi

(I'll need the -lwiringPi switch for my other code.) Unfortunately, I got error messages from the machine trying to link to what may be a library. Message reads:

"/tmp/cc7m8eMe.o: In function 'main': undefined reference to IOPi_init"...

ditto to "set_port_direction" and the other lines of code. (The usleep() function was no problem. ...makes sense. It's looking specifically for I2C stuff.)

I've probably left out something or installed something wrong. ...any ideas? I think I'm missing links to a library of some sort, but am not sure.

Computer geek since 1964. Upgraded to FORTRAN66 back in the day. Downhill ever since.

10/02/2020 Posted by: andrew Location: United Kingdom

You may need to include the ABE_IoPi.c in the gcc command. The command I normally use to compile the demo and test programs is

gcc ABE_IoPi.c test.c -o test

It is often easiest to copy the ABE_IoPi.c, ABE_IoPi.h, ABE_I2CSwitch.c and ABE_I2CSwitch.h into the same directory as your program so you can reference them without needing the full path name.

Another alternative is to create a make file that will include all of the libraries and automatically link everything together.

AB Electronics UK Tech Support

10/02/2020 Posted by: el Ducko Last edited: 10/02/2020 Location: Texas, USA

That worked! Your test.c program compiled, and seems to run okay. However, it failed

IOPi_init(0x20)

and other address number attempts with

Failed to write to i2c device for write

so I'm now wondering if I've fouled up the hardware during soldering..(I shouldn't have used an old high-powered soldering gun from the discrete component days.)

- - -

The IO Pi Plus 2.1 cards get 5 volts okay, externally supplied (jumper un-soldered).. On one card, the address is set to 0x20; that is, solder pads 0/1/2 are not soldered together for either bus 1 or bus 2. (One thing that I see wrong is that bus 2 pads 0 should be soldered together, right?) Due to poor soldering technique on my part, I've fried a couple of the address solder pads, then tried to remove the solder on the remaining ones, and may have fried something in the process. On my second card, I managed to destroy only one of the solder pads, and have connected the "1" pads to set it up for address 22. Looks like I can solder Bus 2 pads 0 together again, so maybe this card can be salvaged too.

So, what are your thoughts? Have I destroyed the cards and will have to buy two more? Will soldering pads 0 together on both cards' bus 2 fix my problem? (...just tried it. Nope- - no joy.) ...any other thoughts?

Computer geek since 1964. Upgraded to FORTRAN66 back in the day. Downhill ever since.

- - -

I’ll skip some of the wailing and gnashing of teeth here. It turns out that I wired up the external power to both expansion boards backward, fried a couple of address pads by overheating them during setting the addresses, then accidentally shorted the 3-volt power supply pin on the Rasberry Pi main board and fried it. This set me back several weeks and a fair amount of money too, although you have to admit, RasPi equipment is pretty inexpensive. Why, back in the mid-60’s…

- - -

20/02/2020 Posted by: el Ducko Location: Texas, USA

Looks like I'm in business now. I ordered two new IO Pi Plus 2.0 boards, soldered in both 40-pin headers and four 20-pin angled headers on the data bus pads, put solder bridges on both of one card's bus address "1" pads, removed the solder bridge from both cards' "link" pads, and soldered some color-coded power leads into both cards' "5V/GND" pads. I stacked 'em on the RasPi board, hooked up the power leads to the 5 volt bus, and fired the machine up. (Actually, I did one card at a time, trying it with the power link still intact so I could draw power off the RasPi, just to make sure. ...didn't want to repeat my earlier errors and fry anything.) Running

sudo i2cdetect -y 1

gave the hoped-for responses. The completed installation detects i2c addresses 20, 21, 22, and 23. Thanks very much for your help, Andrew. I've got a fighting chance, now.

- - -

My next step will be to hook up the ribbon cables to the relay cards and see if they work okay. Hopefully I didn't fry them like I did the other cards. I'll start a different thread, just in case anyone might benefit from my further adventures. As I mentioned, hooking up 20-wire ribbon cable to two ten-pin relay cards requires taking a few liberties with the cable and pin sockets, plus writing a bit of C code. Cross your fingers!

Computer geek since 1964. Upgraded to FORTRAN66 back in the day. Downhill ever since.

04/03/2020 Posted by: el Ducko Last edited: 04/03/2020 Location: Texas, USA

IO Pi Plus 2.1 Connections & Testing

Well, here's that long-awaited post touting success and trumpeting the glories of RasPi and AB Electronics' IO Pi Plus cards. We'll cover the IO Pi Plus 2.1 hardware hookup, how to add relay boards, hardware testing, and a bit of test software.

Installing the AB Electronics Boards

Once my two IO Pi Plus 2.1 32-channel digital expansion HATs for Raspberry Pi were assembled and visually checked out (read about my experiences here, at https://www.abelectronics.co.uk/forums/thread/300/example-c-code-for-io-pi-plus-needed#1175 ) it was time to finish assembly and testing. First step: leave one board with default i2c bus addresses of 20 & 21. Solder jumpers on the second board to set its i2c bus addresses to 22 and 23. Mount the two boards atop the RasPi, using the built-in +5vdc/gnd power and, as Andrew suggested, run

sudo i2cdetect -y 1

to make sure the computer “sees” the boards. Mine ran fine, showing all four buses active.

I powered down, then un-soldered both “link” jumpers, and soldered color-coded wires into the plainly-marked +5vdc/gnd pads on each board. I took a razor saw and cut four separate 20-pin sections off an 80-pin dual-row right angle pin header (part number PLD-80P-P5, no brand name). I got lucky, I guess- - local electronic parts distributor Altex had them. One small warning: when soldering these to the pc boards, you need to leave enough space for the socket connectors to firmly seat on these pins. I suggest you take a female 20-pin connector (see below) and slide it onto the pins before you solder the pins to the board. This way, you can guarantee proper clearance.

80-pin dual row right angle pin headers. Female 20-pin connectors

Wire up the external power supply to the two expansion boards, making sure that you connect with the proper polarity. Check it twice. (This is where I went wrong, fried my two expansion boards, and had to buy new ones.) Power up, boot up, run “i2cdetect” again, and verify that everything checks out okay.

The 80-pin and 20-pin connectors are shown here.