You are browsing the archive for Gertboard.

Avatar of Andrew

by Andrew

The Gertboard: Lesson 5 – Testing the Digital to Analogue and Analogue to Digital Converters

March 4, 2013 in Gertboard, Tutorials

Last time we looked at the Motor Controller. This week we are going to look at the Digital to Analogue and Analogue to Digital Converters.

For this lesson it is suggested that you will need the following items, however they are not essential but both are useful to have for any future projects you may want to embark on:

  • Digital Multimeter
  • Potentiometer

You will also need the test files we used last time. If you don’t have them then follow the instructions in Lesson 2.

Both the analogue converter (D/A) and analogue to digital converter (A/D) are 8-pin chips from Microchip each supporting 2 channels and both use the SPI bus to communicate with the Raspberry Pi. The SPI pins on the two chips are connected to the pins labelled SCLK, MOSI, MISO, CSnA, and CSnB in the header just above J2 on the board. SCLK is the clock, MOSI is the output from the RPi, and MISO is the input to the RPi. CSnA is the chip select for the A/D, and CSnB is the chip select signal for the D/A (the ‘n’ in the signal name means that the signal is ‘negative’, thus the chip is only selected when the pin is low).

Digital to Analogue Converter

The Gertboard uses a MCP48xx digital to analogue converter (D/A) from Microchip. The device comes in three different types: 8, 10 or 12 bits. It is likely that MCP4802, the 8 bit version, will be used, but if higher resolutions are needed, it can be replaced with the MCP4812 (10 bits) or MCP4822 (12 bits). In particular, the routine that writes to the D/A assumes that writes are in 12 bits, so it is important that the value is selected appropriately (details are below in the “Testing the D/A and A/D” section). The maximum output voltage of the D/A – the output voltage when you send an input of all 1s – is 2.04V.

The analogue outputs of the two channels go to pins labelled DA0 (for channel 0) and DA1 (for channel 1) in the J29 header. Just next to these pins are ground pins (GND) to provide a reference.

Analogue to Digital converter

The Gertboard uses a MCP3002 10-bit analogue to digital converter from Microchip. It supports 2 channels with a sampling rate of ~72k samples per second (sps). The maximum value (1023) is returned when the input voltage is 3.3V.

The analogue inputs for these two channels are AD0 (for channel 0) and AD1 (for channel 1) in the J28 header. Just next to these pins are ground pins (GND) to provide a reference.

Testing the D/A and A/D

Digital to Analogue

To test the D/A, a multimeter is required. If you do not have a multimeter you can move on to the next test. The test program for this is dtoa. To set up Gertboard for this test, jumpers are placed on the pins GP11, GP10, GP9, and GP7 connecting them to the SPI bus pins above them. Attach the multimeter as follows: the black lead needs to be connected to ground. You can use any of the pins marked with ⊥ or GND for this. The red lead needs to be connected to DA0 (to test the D/A channel 0 which is shown below) or DA1 (for channel 1). Switch the multimeter on, and set it to measure voltages from 0 to around 5V.


Click Image to Enlarge

So we need to execute the dtoa we do this with the following command:

The program prompts you select a channel to test, for this test we are going to use channel 0:

Next the program prompts you with the connections with you should have connected already, take the time to double check your connections before you proceed:

Now the program will run, it will prompt you 5 times to check the readings on your multimeter there will likely be a variation of about 0.1-0.2v in your readings this is nothing to worry about:

Analogue to Digital

The test program for the A/D is called atod, for this test you will need a potentiometer. If you do not have one you can move onto the last test. To run this test a voltage source on the analogue input is required. This is most easily provided by a potentiometer (a variable resistor). The two ends of the potentiometer are connected, one side to high (3.3V, which you can access from any pin labelled 3V3) and the other to low (GND or ⊥), and the middle (wiper) part to AD0 (for channel 0 as shown below) or AD1 (for channel 1). To use the SPI bus jumpers should be installed on the pins GP11, GP10, GP9, and GP8 connecting them to the SPI bus pins above them (see diagram below).


Click Image to Enlarge

So for this test we need to execute the atod program with the following command:

Next the program will prompt you to select a channel, we will be using channel 0:

Next the program prompts you with the connections with you should have connected already, take the time to double check your connections before you proceed:

Now the program will repeatedly read the 10 bit value from the A/D converter and prints out the value on the terminal, both as an absolute number and as a bar graph (the value read is divided by 16, and the quotient is represented as a string of ‘#’ characters). One thing to be aware of is that even if the potentiometer is not moved, exactly the same result may not appear on successive reads. With 10 bits of accuracy, it is very sensitive, and even the smallest changes, such as house current running in nearby wires, can affect the value read. The output will look something like this:

Digital to Analogue and Analogue to Digital

Next even without a multimeter or a potentiometer, it is still possible to test the A/D and D/A by sending the output of the D/A to the input of the A/D. The test that does this is called dad, for digital-analogue-digital. To set the Gertboard up for this test, hook up all the SPI bus pins (connecting GP11 though GP7 with jumpers to the pins above them) and put a jumper between pins DA1 and AD0, as in the diagram below.


Click Image to Enlarge

So for this test we need to execute the atod program with the following command:

Next the program prompts you with the connections with you should have connected already, take the time to double check your connections before you proceed:

The dad test sends 17 different digital values to the D/A (0 to 255 in even jumps, then back down to 0). The resulting values are then read in from the A/D. Both the original digital values sent and the values read back are printed out, as is a bar graph representing the value read back (divided by 16 as in atod). The bar graph printed out should be a triangle shape, the lines will start out very short, then get longer and longer as larger digital values are read back, then will get shorter again, it should look something like this:

That’s it for this week, next week we will be programming the Atmel ATmega Chip.

As always further detailed information can be found in the Gertboard User Manual.

The wiring diagrams have been taken from the Gertboard User Manual as these are the clearest way to show the connections.

Avatar of Andrew

by Andrew

The Gertboard: Lesson 4 – Testing the Motor Controller

February 13, 2013 in Gertboard, Tutorials

Last week we looked at the Open Collector Driver. This week we are going to look at the Motor Controller.

For this lesson you will need the following items:

  • 1 Small 3v DC Brushed Motor
  • 2 AA Batteries
  • 1 AA Battery Case

You will also need the test files we downloaded last time. If you don’t have them then follow the instructions in Lesson 2.

Setting up


Click Image To Enlarge

To set up the Gertboard for this test, connect GP17 in J2 to the MOTB pin (the MOTB pin in the 2-pin header above GP1 and GP4, not the one at the top of the board), and GP18 to MOTA in that little header. The motor leads need to be connected to the MOTA and MOTB screw terminals at the top of the board, and the power supply for the motor needs to be connected to the MOT+ and ⊥ screw terminals. This is shown clearly in the wiring diagram below.


Click Image To Enlarge

Testing

The test program for the motor controller is called motor. A loop now starts where the PWM is started, first with a very low duty cycle, then gradually increasing this to the maximum. Then the value sent to the PWM is decreased to slow the motor down. Then GPIO17 is set high, so that the motor will get power on the low phase of the PWM signal. The PWM is re-enabled. The reverse polarization flag flips the PWM signal, so that a low value sent to the PWM results in a signal that is high most of the time. That way the same code can be used to slowly ramp up the speed of the motor, then slow it down again. Finally the PWM is switched off, and the GPIO interface is closed down.

Now we are ready to run the test program. We do this by using the following command:

Then it prints out the connections required on the board. Double check you have it set up correctly then hit enter to run:

Then the motor slowly ramps up the speed in one direction, then slows it down again, changes the direction and repeats the process. You will get an output on the screen that looks like this:

That’s it for this week, next week we will be testing the Digital to Analogue and Analogue to Digital Converters.

Suggested items for next week (not essential, but handy to have):

  • Digital Multimeter
  • Potentiometer

As always further detailed information can be found in the Gertboard User Manual.

The wiring diagrams have been taken from the Gertboard User Manual as these are the clearest way to show the connections.

Avatar of Andrew

by Andrew

The Gertboard: Lesson 3 – Testing the Open Collector Driver

February 1, 2013 in Gertboard, Tutorials

First of all sorry for the delay in this post, I have been away on holiday and since I have come back have been quite busy!

Last time we looked at the I/O section of the Gertboard.

This week we are going to look at the Open Collector Driver. For this lesson you will need the following items:

  • At least 2 LED’s
  • 1 resistor
  • 1 9v battery
  • 1 solderless breadboard and some wires or some wires, solder and a soldering iron

You will need to calculate the required resistor based on the supply voltage, in this case 9v from the battery, the forward voltage and current of your LED’s these can be found on the packaging of the LED or the datasheet supplied (where applicable). A useful calculator can be found here.

You will also need the test files we downloaded last time. If you don’t have them then follow the instructions in the previous lesson.

Setting Up The LED Circuit

A simple mechanism was required to switch the driver on and off, so I created a little circuit (see image below) consisting of three LEDs and a resistor in series. Once connected, we will used a 9V battery as a power supply, the forward voltage across each of these LEDs is 1.6V with a 10mA current, so calculated a series resistance of 470Ω to set a suitable current flow through the LEDs.

Since this small test circuit will not be used again I used a solderless breadboard. Remember that LEDs are diodes, and have to be connected the right way round. The small ‘flat’ in the LED moulding denotes the ‘cathode’ or negative pin. If you think of the LED symbol in the circuit diagram below as an arrow, it is pointing in the direction of the current flow, from + to -, or from anode to cathode.

First we need to make sure the circuit we have made is working. Once you are happy that it works we can move on.

To turn the circuit off and on using the open collector driver we are going to use driver 1. So leave the positive side of your circuit attached to the positive terminal of the battery, but in addition connect it to one of the RPWR pins in the headers on the right edge of the board. Disconnect the ground side of the circuit from the power supply and connect it instead to RLY1 in header J12 on the right of the board. Then attach the ground terminal of the power supply to any GND or ⊥ pin on the board.

Now, we need a signal to control the driver. For the ocol test program we are using GPIO4 to control the open collector (you could of course use any logic signal), so connect GP4 in header J2 to RLY1 in J4. See the wiring diagram below for a clear picture of how it should connect up to the Gertboard.


Click Image To Enlarge

Testing

Now we come to testing the open collector driver. When RLY1 in J4 is set low, the circuit doesn’t receive any power and thus is off. When RLY1 in J4 goes high, the open collector driver uses transistors to connect the ‘ground’ side of the circuit to the ground on the board, and since this is connected to the ground terminal on the power supply, the power supply ends up powering the circuit: it is just turned off and on by the open collector driver.

Now we are ready to run the test program. We do this by using the following command:

Then it asks which driver we would like to use, we are going to use driver 1:

Then it prints out the connections required on the board (and with your external circuit and power supply). Double check you have it set up correctly then hit enter to run:

The program sets GPIO4 high then low 10 times essentially turning the LED’s off and on.

That’s it for this week! Next week we are going to test the Motor Controller and again we are going to need a few extra components:

Shopping List

  • 1 Small 3v DC Brushed Motor
  • 2 AA Batteries
  • 1 AA Battery Case

As before further detailed information can be found in the Gertboard User Manual.

The wiring diagrams have been taken from the Gertboard User Manual as these are the clearest way to show the connections.

Avatar of Andrew

by Andrew

The Gertboard: Lesson 2 – Testing the Buffered I/O Section

January 14, 2013 in Gertboard, Tutorials

Last week we looked at the layout of the Gertboard.

This week we are going to test the three parts of the buffered input/output section of the Gertboard: The Pushbuttons, the LED’s and the Input/Output capabilities. But first we will need to obtain the files.

Obtaining the Required Files

First we will need to obtain the code for all the test examples, there is a link in this post to the required files. These files have been re-written in Python by Alex Eames but for the purposes of these lessons we will be using the ones written in C by Gert van Loo.

If you have not downloaded the files directly onto your Raspberry Pi, you will need to copy them over using your preferred method. Next you will need to locate the file on your Pi then run the following commands in the terminal:

unzip gertboard_sw_20120725.zip

cd gertboard_sw

make all

Now you will need to check what revision of Raspberry Pi board you have, the easiest way to do this is to look at you Pi and if it has two mounting holes on the board then it’s a Rev2 if it has none it’s a Rev1. If you have a Rev 2 board then you will first need to make an amendment to the LED.C file as described in the above post that you got the files from. The reason for this is they changed the GPIO pin from 21 to 27 on the Rev2 boards. If you have a Rev2 and do not make this change then the 5th LED will not light up.

Note: Be aware the LED’s often behave randomly this is just an unintended feature of the board. They can easily switch state, switching on or off with the smallest of electronic changes, for example, moving your hand close to the board.

Testing the Pushbuttons

The test program for the pushbutton switches is called buttons. To run this test, the Gertboard must be set up as in the image below. There are straps connecting the following pins in header J3 to the pins in header J2:

B1 to GP25
B2 to GP24
B3 to GP23


Click Image To Enlarge

Thus GPIO25 will read the leftmost pushbutton, GPIO24 will read the middle one, and GPIO23 will read the rightmost pushbutton. The jumpers on the ‘out’ area of U3 (U3-out-B1, U3-out-B2, U3-out-B3) are optional: if they are installed, the leftmost 3 LEDs will light up to indicate the state of the switches.

Now run the following command:

 

So when a button is pressed the 1 will change to a 0 indicating that the circuit has been closed then returning to 1 when the button is released. There will be an output on the screen like this:

 

 

Testing the LEDs

The test program for the LEDs is called leds. To set up the Gertboard to run this test, see the wiring diagram below. Every I/O port is connected up as an output, so all the ‘out’ jumpers (those above the buffer chips) are installed. Straps are used to connect the following (where all the ‘GP’ pins are in header J2 and all the ‘B’ pins are in header J3):

GP25 to B1     GP22 to B4     GP17 to B7     GP9 to B10
GP24 to B2     GP21 to B5     GP11 to B8     GP8 to B11
GP23 to B3     GP18 to B6     GP10 to B9     GP7 to B12


 Click Image To Enlarge

In other words, the leftmost 12 ‘GP’ pins are connected to the ‘B’ pins, except that GP14 and GP15 are missed out: they are already set to UART mode by Linux, so it’s best if they are not touched.

Now run the following command:

 

The output from this example is the lights will flash back and forth similar to that of a Cylon from Battlestar Galactica or KITT from Knight Rider.

Testing I/O

Our two examples so far have only used the ports to access the pushbuttons and LEDs. The next example, called butled (for BUTton LED) will show one of the ports serving just as an input port. The idea is that one port (along with its button) is used to generate a signal, and software then sends that signal to another port which it is used as just an input. We read both ports in and print them on the screen.

GPIO23 to B3     B3(OUT) to BUF6
GPIO22 to B6     Jumper on B6(IN)


Click Image To Enlarge

The wiring for this test is shown above. The pushbutton on port 3 is going to be used here, but the LED for port 3 should not be used, so therefore the output jumper for port 3 is not installed (which would be placed at U3-out-B3).

Now run the following command:

 

The output from this example is something like this:

 

 

 

Only button 3 (the right one) is used in this example. So when the test is started with button 3 up, 11 is displayed, and then the button is pushed down, occasionally 01 might be seen, followed very quickly by 00.

That’s it for this week, hopefully all went well! Next week we will be testing the Open Collector Driver and you will need a few extra components.

Shopping List (Edit)

  • At Least Two LEDs
  • A Resistor
  • A 9v Battery

As before further detailed information can be found in the Gertboard User Manual.

The wiring diagrams have been taken from the Gertboard User Manual as these are the clearest way to show the connections.

Avatar of Andrew

by Andrew

The Gertboard: Lesson 1 – Getting To Know Your Gertboard

January 2, 2013 in Gertboard, Tutorials

First of all Happy New Year 2013 to all of you from the Tech-Fruits team! :D

Welcome, my name is Andrew Sindle-Mouat (@ASindleMouat) and over the coming weeks I will be talking you through the Gertboard, some small test programs for each of the sections of the board and (looking ahead) some small projects utilizing the components on the Gertboard.

Some of you, like myself, may have been lucky enough to receive a Gertboard when they were first released and had the excitement of assembling this board yourself. However the board is no longer available to buy disassembled but should be available to buy fully assembled in the new year.

“The Gertboard is an add-on GPIO expansion board for the Raspberry Pi computer. It comes with a large variety of components, including buttons, LEDs, A/D and D/A converters, a motor controller, and an Atmel AVR microcontroller.”

So below are the six main areas of the board:

1) GPIO Pins

This is where you connect to your Raspberry Pi’s GPIO pins to the J1 header using a 24pin ribbon cable which should be provided with your board. The GPIO pins can still be accessed on the J2 header just above the J1 header. Each pin number is shown below the corresponding pin.

2) Buffered I/O, LEDs, and Pushbuttons

Here you have 3 Push-buttons, 12 red LED’s and 12 pins which can be used as input or output ports. Each pin can be set to behave either as an input or an output simply by using a jumper. The terms input and output in this section relate to the connection with the Raspberry Pi, so the Input, inputs to the Raspberry Pi and the Output, you guessed it, outputs from the Raspberry Pi.

3) Open Collector Driver

The Gertboard uses six of the eight ports of a ULN2803a Darlington Array chip to provide open collector drivers. These are used to turn off and on devices, especially those that need a different voltage or higher current than that available on the Gertboard and are powered by an external power supply. The ULN2803a can withstand up to 50V and drive 500mA on each of its ports.

4) Motor Controller

The Gertboard uses an L6203 (Miniwat11) motor controller for brushed DC motors. The controller has two input pins, A and B (labelled MOTA and MOTB on the board). The pins can be driven high or low, and the motor responds according to the table below. The speed of the motor can be controlled by applying a pulse-width-modulated (PWM) signal to either the A or B pin. The motor controller IC has internal temperature protection and Current protection is provided by the fuse on the Gertboard.

5) Digital to Analogue and Analogue to Digital Converters

The Gertboard has an MCP4801 8-bit digital to analogue (D/A) converter and a MCP3002 10-bit analogue to digital (A/D) converter both are 8-pin chips from Microchip. The D/A chip is located at U6 and the A/D chip is located at U10. Each chip supports 2 channels and both use the SPI bus to communicate with the Raspberry Pi.

6) ATmega device

The Gertboard has an ATmega328P Atmel AVR microcontroller, a 28-pin ATmega device located at U8 on the board. All input/output pins for the chip are brought out to header J25 on the board. There is a separate 6-pin header located at J23 that can be used to program the device. The PD0/PD1 pins (ATmega UART TX and RX, labelled MCTX and MCRX on the board) are brought out to pins placed adjacent to the Raspberry Pi UART pins (labelled GP14 & GP15) so you only need to place two jumpers to connect the two devices.

Warning: An important point about the ATmega device on the Gertboard is that it operates at 3.3Volts. That is in contrast to the ‘Arduino’ system which runs at 5V. Many of the Arduino example sketches (programs) mention +5V as part of the circuit. Because we are running at 3.3V, you must use 3.3V instead of 5V wherever the latter is mentioned. If you use 5V you risk damaging the chip.

That’s it for this week. Next week we will look at a few test programs for the Buffered I/O section of the board.

Further detailed information can be found in the Gertboard User Manual.