Home
Gertboard User Manual
Contents
1. 1 S SS 6666 Mi ngesod 86966 0000 sl p 4 Heal NO A 49 6 eje eje e e Ss meee Hooccccoce0 ooo OTE CIIITID ZH EO Ho EE sE 0000000000 110 ERIS T Et 2000000000 2 a soor J ont S28 CRM Raspberry Pi 1 0 extension 11 March 2012 B 0 Developed by G J van Loo Fen Logic Ltd 000000 08 Fig 29 Wiring diagram for the sketch AnalogInSerial AnalogReadSerial GPIO14 and 5 are the pins that the Raspberry Pi uses for the UART serial port If you refer back to the table of alternate functions on page 9 you will see that GPIO14 is listed as TX and 15 as RX This is not a mistake This swapping is necessary the data that is transmitted by the ATmega is received by the Raspberry Pi and vice versa Now how to we get the Raspberry Pi to read and show us the data that the ATmega is sending out on the serial port There is a button labelled Serial Monitor on the toolbar of the Arduino IDE but it doesn t work on the Raspberry Pi It assumes that you are talking to an Arduino board over USB not talking to a Gertboa
2. Roc 4 9021 34101 W 31OH LHIN 9080 50001 49 Ul 2 0 9 4 001 9080 50001 L x81938 80807401 9080 404 9080 50001 9080 50001 9021 3101 59 lt dSVH dSVH AS pub ur HOION HOLOMW E 2 I sions esn oq 9 Av 13H Av 13H nmm amp Av 3H 9 8Old ScOld9o 220 90 9 dSVH AS dSVH JequinN jueuin2oq AL OZNY YMS TREES 2 8 2 KE ana A 25 Kz ana 8 NuH uos AL LE N 9080 9001 9080 9001 9080 9001 019 69 89 ve Lec Lec Liz 6 81 __ vi 1 2 8 QvNu N HOLL O9NY IXENS3H lt 6 4ng LXPNSSY Y Sa lt Sang LXPNSSY s JequinN ezi en V 082N I1 9 Av 13H AVI3H amp s JequinN
3. mol 29 Cii 1 7 5 600009 22 52452242 B6 4 Raspberry Pi 1 0 extension 11 March 2012 e e Developed by G J van Loo Fen Logic Ltd Fig 12 This type of diagram is much more effective at showing how straps connect pins together on the board so from now onwards we will use these type of diagrams to show wiring arrangements 15 In the diagram black circles show which pins being connected and black lines between two pins indicate that jumpers if they are adjacent or straps if they are further apart are used to connect them The code specific to the buttons testis buttons c In the main routine the connections required for this test are firstly printed to the terminal a text description of the wiring diagram above When the user verifies that the connections are correct setup io is called described on page 10 to get everything ready setup_gpio is then called which gets GPIO pins 1 to 3 ready to be used as pushbutton inputs It does this by first using the macro _ n where n is GPIO pin number to select these 3 pins for input Then pins are required to be pulled high the buttons work by dropping the voltage down to 0V when the button 15 pressed so it needs to be high when the button is not pressed This is done by setting
4. ezi en ubru exeu sjeu 2190 10 S080 uzc MW 0297 97 JNQ cNOO pieoque5 1 af JNQ cNOO ANG ENOOD ANG ENOOD ANG ENOOD zl Lor __ 1 2 2 2 2 2 D D D 69r sor zor gor sor ANG ENOOD ANG ENOOD 1 A 21 21 2 2 2 D D cor eor 89 29 oor 2 E 2 JNQ cNOO vor esr rer 5 2 Q JNQ cNOO JNQ cNOO JNQ NOO Lyn JNQ cNOO JNQ cNOO JNQ cNOO 5 2 2 or 22 o o 9 JNQ cNOO JNQ cNOO JNQ cNOO JNQ cNOO LL z E 2 2 zer ger ser ver 9 JNQ cNOO JNQ cNOO JNQ cNOO JNQ cNOO E N 2 o 2 oer 5 JequinN jueuin2oq 89d NNOO 97 XL OW XH OW SS 5 9 1
5. 803a Fig 1 The principle high level diagram of the Gertboard In this view it is possible to see how flexible Gertboard is by being able to connect various parts of the board together Above is a principle diagram of the Gertboard Each circle in the diagram represents a header pin These headers give you access to a wide range of control combinations As you begin experimenting with the board you will probably use the strapping area to connect various components on the Gertboard to the Raspberry Pi This flexibility even allows you for example to connect the motor controller input pins to the Atmel ATmega device an AVR microcontroller The ATmega device has a separate 6 pin header which allows it to be programmed by the Raspberry Pi using the Serial Peripheral Interface SPI bus The major building blocks are e 12x buffered I O e 3x push buttons e 6x open collector drivers SOV 0 5A e 48V motor controller 28 pin dual in line ATmega microcontroller 2 channel 8 10 12 bit Digital to Analogue converter 2 channel 10 bit Analogue to Digital converter Each of these building blocks has a section below A principle diagram is a coarse overview of the most important parts of the system It is not correct in all details For that you must look at the board schematics Labels on the circuit board NC EE c 5 2 5 5 ari c slo ala
6. SO 0000000000 nae ege u OILI E PB3 4 Bi B20ut a3 B4 RNS male ft SER ojm 1755 meel Ss meee ef 9900000000 mee ee e je x P3ee 21 Ne your circuit 02 e T 6 6 6 6 goes here IW mue em S 5 in oT 5 CI7R24 E 6 source 5 goes here EM e Raspberry Pi 00000000000 8 PCI 1 0 extension 5555555555 565656666 5 March 2012 O m 2 822228222244 5 4 Fig 16 Wiring diagram showing how to connect Gertboard to test the open collector drivers It also shows the small test power supply made up of two LEDs in series a 90 resistor and a 9V battery You may wonder why you need to connect the positive terminal of the power supply to the open collector driver via the RPWR pin The reason for this is that if the circuit happens to contain an component that has electrical inductance for example a motor or a relay when the power is turned off this inductance causes the voltage on RLYn pin to quickly rise to a higher voltage than the positive te
7. _ INIV ZGOd 94 9190 SS d VZOO ISOW LL 8000 SQd vad VZOO OSIN 21 1 298 584 95 09d 090V OL MOX v Qd 8290 LLNI EQd 4 OLNI ZQd 0d EOdV D _ qxu oad 604 105 400 1 3 5 90 9080 50001 029 9080 50001 619 40 EUOS9I 190
8. Raspberry Pi 1 0 extension 11 March 2012 B Developed by G J van Loo Fen Logic Ltd 000000 08 Fig 28 Wiring diagram for AnalogInput sketch Minicom Some of the Arduino sketches involve reading or writing data via the serial port or UART An example is AnalogInSerial under File gt Examples gt Analog for version 0018 In version 1 0 1 this same example has been renamed AnalogReadSerial and is under File gt Examples gt Basics This sketch sets the baud rate to 9600 then repeatedly reads in a value from analogue pin 0 and prints this value to the serial port also called UART The value read in is between 0 and 1023 0 means that the input pin is at OV and 1023 means that it is at the supply voltage 3 3V for the Gertboard To set up your Gertboard for this sketch you need the potentiometer attached to analogue input 0 as described above In addition you need to connect the ATmega chip s pins to the Raspberry Pi Digital pin 0 PDO on the Gertboard is RX receive and digital pin 1 PD1 on the Gertboard is TX transmit These signals are also brought out to the pins labelled MCTX and MCRX just above the GP15 and GP14 pins in header J2 on the Gertboard Thus you can use two jumpers to attach the A Tmega s TX to GP15 and RX to 14 as shown below 36 lt gt oo a e i b
9. m 59 mm 48499 k 5 H H E Fuse 4A C MP T U4 222222022 e commo Raspberry Pi 1 0 extension 11 March 2012 e 5 3 Developed by G J van Loo Fen Logic Ltd 000000 H Fig 14 The wiring diagram for test program but led which detects a button press and then display that button state on the screen This is to test all the I O on the Gertboard The wiring for this test is shown above Pin GPIO23 controls I O port 3 and GPIO22 controls I O port 6 so GP23 in header J2 is connected to pin B3 in header J3 and GP22 is connected to B6 Now for the interesting part 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 18 Looking at the schematic on page 2 it is clear that the output buffer for port 3 goes to pin 14 of buffer chip U3 This is connected to the U3 out B3 header pin just above pin 14 on the chip it is pin 1 of U3 out B3 this is clear from the schematic and from the fact that this pin has a square pad on the bare circuit board so that pin is connected to the BUF6 pin at the top of the board This allows the switch to generate a signal which is then sent to port 6 A jumper is installed across U4 in B6 to allow that sign
10. 20 The wiring diagram for the test program motor The code for the motor program is in motor c Inthe main routine first the connections that must be made on the board to run this program are printed out then call setup io to get the GPIO interface ready for use setup gpio is then called to set GPIO18 up for use as PWM output and GPIO17 up for normal output For the latter both GPIO and OUT GPIO are used see page 11 for more info To set up GPIO18 first use _ 18 to activate the pin One of the alternate functions for 18 is to act as the output for the this is alternative 5 Thus use the macro SET GPIO ALT 18 5 to select this alternate use of the pin See table Table 6 31 from the 2835 datasheet or the online version at http elinux org RPi_BCM2835_GPIOs for more details about alternative functions for the GPIO pins A summary of the alternate function of GPIO pins used on the Gertboard see the table on page 9 24 We set the output of 17 low to make sure that the motor doesn t turn and then initialize the PWM by calling setup_pwm We enable the PWM by setting the mode to PWMO_ENABLE using force_pwm0 Since GPIOI7 motor controller B input is set low when the duty cycle on the PWM motor controller A input is high enough the motor will turn the opposite way as described in the motor table on page 22 A loop now starts where the PWM is
11. 4 14 and 15 are used To set them up for output first call _ where n is GPIO pin number for each of the 12 pins to activate them This also sets them up for input so then call OUT GPIO n afterwards for each of the 12 pins to put them in output mode LEDs are switched on using the macro GPIO_SETO the value assigned to SETO will set GPIO pin n to high if bit is set in that value When GPIO pin is set high the I O port connected to that pin goes high and the LED for that port turns on Thus the line of code SETO 0x180 will set GPIO pins 7 and 8 high since bits 7 and 8 are set in the hexadecimal number 0x180 Given the wiring setup above ports 11 and 12 will go high because these are the ports connected to GP7 and GPS and thus the rightmost two LEDs will turn on To turn LEDs off use macro CLRO This works in a similar way to SETO but here the bits that are high in the value assigned to CLRO specify which GPIO ports will be set and hence which ports will be set low and which LEDs will turn off So for example given the wiring above the command GPIO CLRO 0x100 will set GPIO8 pin low and thus turn off the LED for port 11 which is the port connected to GP8 In leds the LEDs are always all turned off together but they don t have to be used this way The test program flashes the LEDs in three patterns The patterns are specified
12. for using this port if neither the input nor output jumper is placed the I O pin can be used as a simple logic detector The I O pin can be connected to some other logic point i e one that is either at OV or 3 3V and use the LED to check if the connect point is seen as high or low Depending on the type of 74xx244 buffer chosen the LED could behave randomly if the port is not driven properly In that case it may easily switch state switching on or off with the smallest of electronic changes for example when the board is simply touched There is a series resistor between the input buffer and the GPIO port This is to protect the BCM2835 the processor on the Raspberry Pi in case the user programs the GPIO as output and also leaves the input jumper in place The BCM2835 input is a high impedance input and thus even a 10K series resistor will not produce a noticeable change in behaviour when it is used as input Push buttons The Gertboard has three push buttons these are connected to ports 1 2 and 3 Thus the first three I O ports look like this 74xx244 Joutput 1k e Fig 9 Circuit diagram showing one of the three push buttons I Os There is a circuit like this for ports 1 to 3 In order to use a push button the input jumper must not be installed even if the intention is to use this as an input to the Raspberry If it is installed the output of the lower buffer prevents the pushbutton
13. if a second value is written again quickly the first will have no effect The force 0 routine takes two arguments new value and a new mode It disables the PWM then sets the value then re enables it with the given mode setting 23 with delays in strategic places to allow the new values to be picked up pwm_of f routine simply disables the PWM The test program for the motor controller is called mot or To set up Gertboard for this connect 17 in 12 to the MOTB pin the MOTB pin in the 2 pin header above 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 L screw terminals This is shown below your power source goes here 3v3 e e o D gt 4090000000640 pone 224 eae et OIIO y B T ls we uid SE SEEE does E Dx wo Ho min ome 6660600000 n gt 2000000000 v E OE ojm ojm 70000000 1 4 LN B B2in B3 o 15 C16 Raspberry Pi 1 0 extension 11 March 2012 v3 Developed by G J van Loo Fen Logic Ltd nm H Fig
14. Atmel chip The supply voltage the voltage that acts as high or logical 1 on the board is 3 3V This is generated from the 5V power pin in the J1 header the one where the ribbon cable to the Raspberry Pi is attached by the components in the lower right corner of the board The open collector and motor controllers can handle higher voltages and have points to attach external power supplies Jumpers and straps lt gt Fig 6 Image showing straps on the left hand side and jumpers on the right Straps connect two parts of Gertboard together whilst jumpers conveniently connect two adjacent pins on the same header together The Gertboard Kit contains materials to produce single straps although the double strap also shown can also be useful To work properly and get the maximum flexibility from the Gertboard a number of straps and jumpers are essential On the left of the photo are straps they consist of wires that connect the small metal connector and plastic housing that slip over the header pins They are meant for connecting header pins that are further apart It is sometimes useful to have straps that connect two or three adjacent pins to the same number of adjacent pins elsewhere on the board This is useful for example when you want to use several LEDs On the right of the above photo are jumpers they are used to connect two header pins that are right next to each other There is one jumper that should be in place at all times
15. GPIO PULL to 2 the code for pull up Should it ever be required the code for pull down is 1 The code for no pull is 0 this will allows this pin to be used for output after it has been used as a pushbutton input To apply this code to the desired pins set PULLCCLKO 0X03800000 This hexadecimal number has bits 23 24 and 25 set to 1 and all the rest set to 0 This means that the pull code is applied to GPIO pins 23 24 and 25 A short wait allows time for this to take effect and then GPIO PULL and GPIO PULLCLKO are set back to 0 Back in the main routine a loop is entered in which the button states are read using macro GPIO INO grabbing bits 23 24 and 25 using a shift and mask logical operations and if the button state is different from before it is printed out in binary up high is printed as 17 and down low is printed as 0 This loop executes until a sufficient number of button state changes have occurred After the loop unpull pins iscalled which undoes the pull up on the pins then call restore ioingb common c to clean up Testing the LEDs The test program for the LEDs is called 1eds 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 pins are in header J2 and all the B pins a
16. an Arduino sketch that assumes that the button reads 1 when pressed the best approach is to modify the sketch if needed so that it will invert the value it reads from the button For the pull up we can take advantage of the pull ups in the ATmega chip To do this find the lines below in the sketch initialize the pushbutton pin as an input pinMode buttonPin INPUT and insert the following two lines after them set pullup on pushbutton pin digitalWrite buttonPin HIGH To invert the value read from the button find the line below buttonSate digitalRead buttonPin and insert a the negation operator in C as follows buttonSate digitalRead buttonPin Now upload this modified sketch as described for Blink We still need to attach Arduino digial pin 2 PD2 on the Gertboard as you can see from the table to a button say button 3 The Raspi pin in the circuit diagram above which is where we want to read the value is in the J3 header 34 o 2 9 f lt ss d wie ti 0000 Fuse max 4A i 5 TM m A 4 asd dus me Em 49 le eje ele e e n non 290929996 mememeome mare me il ou S 0000000000 05 BI e Raspberry Pi 1 0 extension 11 M
17. fast motor speeds by varying the value sent to the PWM Decoder The decoder implemented by the decoder program takes the three pushbuttons as input and turns on one of 8 LEDs to indicate the number with the binary encoding given by the state of the buttons Switch S1 gives the most significant bit of the number S2 the middle bit and S3 the least significant bit For output the LED D5 represents the number 0 D6 represents 1 and so on so D12 represents 7 Recall that the pushbuttons are high 1 when up and low 0 when pushed so LED D12 is lit up when no buttons are pressed giving binary 111 or 7 D6 is lit up when S1 and S2 are pressed giving binary 001 etc There is quite a bit of wiring for this one as we are using all but one of the I O ports GPIO25 to GPIO23 are reading the pushbuttons so you need to connect GP25 to B1 GP24 to B2 and GP23 to B3 The 8 lowest numbered GPIO pins are used with I O ports 5 to 12 so you need to connect GP11 to B5 GP10 to B6 GP9 to B7 GP8 to B8 GP7 to B9 GP4 to B10 GP1to B11 and to B12 In addition since we are using I O ports 5 to 12 for output you need to install all the out jumpers for buffer chips U4 and 05 recall that the out jumpers are those above the chips 39 geese a xr H T 5 s FI Fuse max AUT mn einen 2222 Wa uM _______ 69
18. in this guide because it is much clearer to see the diagram shown in Fig x will be used in preference to show you how to wire up the Gertboard and to run the test and example programs It is useful to be able to look at the bare board in order to see the labels the white text in the photo and the blue text in the diagram on the board without the components getting in the way These labels provide essential information that is required in order to use Gertboard to its full potential Almost all of the components have labels and more importantly the pins in the headers have labels It isn t necessary to be too concerned about the majority of the components such as resistors and capacitors labelled with Cn and Rn where n is some number These are fairly simple devices that don t have a right way round when they are assembled to the board Diodes on the other hand do need assembling the right way round covered later all the diodes are labelled Dn of these the ones that you will be interested in are D1 through D12 the light emitting diodes LEDs they are located near the top of the board on the left Pushbutton switches are labelled 51 52 and 53 they are located just beneath the LEDs 8 7 6 5 20 19 18 17 16 15 14 13 12 11 1
19. integer with the value read from the A D converter The value returned will be between 0 and 1023 i e only the least significant 10 bits are set with 0 returned when the input pin for that channel is and 1023 returned for 3 3V The write dac routine takes two arguments a channel number 0 or 1 and a value to write The value written requires some explanation The MCP48xx family of digital to analogue converters all accept a 12 bit value The MCP4822 uses all the bits the MCP4812 ignores the last two and the MCP4802 which is probably the one you are using ignores the last four Since you could use any of those chips on the Gertboard write dac is written in so that it will work with all three so it simply sends to the D A the value it was given If Gertboard is fitted with the MCP4802 it can only handle values between 0 and 255 but these must be in bits 4 through 11 assuming the least significant bit is bit 0 of the bit string it is sent Thus if the desired number to be sent to the D A is between 0 and 255 it must be multiplied by 16 which effectively shifts the information 4 bits to the left before sending this value to write dac The value on the output pin Vout is given by the following formula assuming the 8 bit MCP4802 Vout D x 2 948y 256 To test the D A a multimeter is required The test program for this is dt oa set up Gertboard for this test jumpers are placed on the pins GP11 GP10 GP9 and GP7 conne
20. into the Arduino IDE Finally you have to program the fuses on the ATmega chip Happily Gordon has written some scripts to do all this for you Full instructions scripts and the modified avrdude are available at https projects drogon net raspberry pi gertboard We assume now that you have downloaded and successfully installed and configured the Arduino IDE as described above and we proceed from there To get going with the ATmega chip start up the Arduino IDE This should be easy if the installation of the Arduino package was successful you will have a new item Arduino IDE in your start menu under Electronics The exact version of the IDE you get with depends on the operating system you are using The version number is given in the title bar The Debian squeeze package is version 0018 while the wheezy package is 1 0 1 First you will need to configure the IDE to work with the Gertboard Go to the Tools gt Board menu and choose the Gertboard option with the chip you are using ATmegal68 or ATmega328 For IDE version 1 0 1 you will also have go to the Tools gt Programmer menu and choose Raspberry Pi GPIO Arduino pins on the Gertboard the input and output pins of the ATmega chip are brought out to header J25 on the left edge of the board They are labelled PDn and PBn where n is a number These labels correspond to the pinout diagrams of the ATmegal68 328 chips However in the Arduino world
21. on the board the one connecting pins 1 and 2 in header J7 This is the jumper that connects power from the power input pins to the rest of the board It is near the lower right corner of the board and is the jumper connecting the two pins below the text 3V3 in the photo below Fig 7 Image showing header J7 with translucent jumper in place J7 is located just above J8 J7 legend is obscured in this image GPIO pins The header J2 to the right of the text Raspberry Pi on the board provides access to all the I O pins on the GPIO header There are 26 pins in J1 the GPIO header which is connected to the Raspberry Pi through the ribbon cable but only 17 pins in J2 3 of the pins in J1 are power and ground and 6 are DNC do not connect The labels on these pins GPO GP1 GP4 GP7 etc may initially seem a little arbitrary as there are some obvious gaps and the numbers do not correspond with the pin numbers on the GPIO header J1 These labels are important however they correspond with the signal names used by the BCM2835 the processor on the Raspberry Pi Signal GPIOn on the BCM2835 datasheet corresponds to the pin labelled on header J2 so for example GPIO17 on the data sheet can be found at the pin labelled GP17 on the board The numbers in the labels allow us to specify which pins are required in the control programs to be run later Some of the GPIO pins have an alternate function that are made use of in some of the tes
22. started first with a very low duty cycle because the value passed to set_pwm0 is low then gradually increasing this to the maximum which is set to 0x400 1024 setup_pwm 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 with the mode PWMO_ENABLE PWMO_REVPOLAR 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 rather than low most of the time That way the same code can be used to slowly ramp up the speed of the motor but in the one way direction as in the table on page 22 then slow it down again Finally the PWM is switched off and the GPIO interface is closed down Digital to Analogue and Analogue to Digital Converters In the Gertboard building blocks diagram on page 7 the components implementing the converters are outlined in orange Both the analogue converter D A and analogue to digital converter A D are 8 pin chips from Microchip The D A is U6 above and the A D is U10 below Each supports 2 channels 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 thus in the building blocks diagram these pins are also outlined in orange SC
23. table showing the behaviour of the motor controller under different logic combinations The motor controller IC has internal temperature protection Current protection is provided by a fuse on the Gertboard The motor controller is in the schematics on page A 4 On the Gertboard building block diagram on page 7 the area containing the components for the motor controller are outlined in purple The motor controller and screw terminals are near the top of the board and there are two pins for the control signals in a small header just above GP4 and in header J2 The MOTA and MOTB pins just above header J2 are the inputs to the motor controller these are digital signals low and high The screw terminals at the top of the board labelled MOTA and MOTB are the outputs of the motor controller they actually provide the power to the motor The motor will probably need more power a higher voltage or current than that provided by the Gertboard The screw terminals at the top labelled MOT and L allow the connection of an external power supply to provide this the motor controller directs this power to the MOTA and MOTB screw terminals modulating it according to the MOTA and MOTB inputs near J2 If you just want to turn the motor off and on in either direction this is achieved by simply choosing two of the GPIO pins and installing straps between them to the MOTA and MOTB motor controller inputs Then to control the motor the pins are set hi
24. the pins of the chips are not referred to directly Instead there is an abstract notion of digital and analogue pin numbers which is independent of the physical devices This allows code written for one Arduino board to be easily used with another Arduino board which may have a chip with a different pinout Thus in order to use your Gertboard with the Arduino IDE you need to know how the Arduino pin number relates to the labels on your Gertboard The table below shows this correspondence means Gertboard 30 Arduino Pin GB pin Arduino Pin GB pin Arduino Pin GB pin digital 0 PDO digital 7 PD7 analogue 0 AO PCO digital 1 PD1 digital 8 PBO analogue 1 Al digital 2 PD2 digital 9 analogue 2 2 2 digital 3 PD3 digital 10 PB2 analogue 3 A3 PC3 digital 4 PD4 digital 11 PB3 analogue 4 A4 PC4 digital 5 PDS digital 12 PB4 analogue 5 A5 5 digital 6 PD6 digital 13 5 Table 4 The relationship between pins on Arduino and pins on Gertboard In both versions of the Arduino IDE digital pins are referred to in the code with just a number For example digitalWrite 13 HIGH will set pin 13 PB5 on the Gertboard to logical 1 In the Arduino world LOW refers to logical 0 and HIGH refers to logical 1 The analogue pins are handled slightly differently In version 0018 analogue pins are referred to simply by number so whether 0 refers to PDO a digita
25. to the point labelled I O on that diagram Recall that the pins corresponding to these points are BUF1 to BUF12 in the unlabeled single row header at the top of the Gertboard So if you connect PB5 to BUF1 as below the first LED will start to blink 32 6949 asas g 1 5 9 imm 4 n Dpi 222254 ee pO 9 B Aw op C uje mn ejm e 0000009 95 HOII DERT ejm ejm e B2 B3 B4 6 00 610 01299900 4 H 5234338 15 C16 S RLY4 RLY5 RLY6 Raspberry Pi 1 0 extension 11 March 2012 e e 3v3 Fen Logic Ltd Developed by G J van Loo Hs Fig 24 Wiring diagram for the sketch Blink Note that in this diagram we have not shown the connections to the SPI pins Once you have uploaded the code you no longer need them and can remove the straps On the other hand if you want you can leave them in place and this is a good idea if you are planning on uploading some other sketches later Let s look at another fairly simple sketch called Button located under File Examples Digital menu in both 0018 and 1 0 1 The comments at the beginning of the sketch read The circuit LED attac
26. 2 3 4 12 3 4 5 6 7 8 910 Fig 4 Two examples of ICs 8 pin and 20 pin dual inline DIL package In this package style pin 1 is always identified as the first pin anticlockwise from the package notch marking Integrated circuits or ICs are marked Un so for example the I O buffer chips U3 U4 and 05 these are near the middle of the board while the Atmel microcontroller is U8 this is below and to the left of U3 to 05 For the ICs it is very important to know which is pin 1 If the IC is orientated so that the end with the semi circle notch is to the left then pin 1 is the leftmost pin in the bottom row On the Gertboard the location of pin 1 is always marked with a square pad Pin numbers increase in an anti clockwise direction from there as shown in the diagram Knowing this means that the schematics in Appendix A can always be related to the pinning on the ICs on the Gertboard Headers the rows of pins sticking up from the board will be a frequently used component on the Gertboard They are labelled Jn so for example the header to the ribbon cable from the Raspberry Pi is attached is J1 Pin 1 on the headers is again marked with a square pad Power pins are marked with their voltage for example there are a few positions marked 3V3 This is a commonly used notation in electronics and in this case it means 3 3 volts 5 power supply comes onto the board via the GPIO connector but the standard Gertboard assembl
27. 81 20 9000009 nas 99292992592 B6 S B2 B3 B4 Raspberry Pi 1 0 extension 11 March 2012 ej 3v3 Fig 31 Wiring diagram for the decoder test In the main routine for decoder as always we start out by printing out to the terminal the connections that need to be made on the Gertboard Then we call setup io to set up the GPIO ready for use Then we call setup gpio to set GPIO25 to 23 for use with the pushbuttons by selecting them for input and enabling a pull up as described on page 16 and to set GPIO11 to GP7 GPIO4 and GPIOO up as outputs as described on page 11 Then we enter a loop where we read the state of the pushbuttons and light up the LED corresponding to this number after turning off the LED previously set We turn the LEDs on and off using GPIO_SETO and GPIO CLRO as described on page 17 For More Information For further information the datasheet for the processor can be found here http www raspberrypi org wp content uploads 2012 02 BCM2835 ARM Peripherals pdf Appendix A Schematics We have included the schematics for the Gertboard in the pages that follow They are numbered A 1 A 2 etc The page number is located in the lower left hand of each page 40
28. FEN LOGIC LTD Gertboard User Manual Gert van Loo and Myra Vanlnwegen Revision 1 0 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 There is a suite of test example programs for the Gertboard written in C which is freely available at www element14 com raspberrypi This manual explains both how to set up the Gertboard for various control experiments and also explains at a high level how the test code works Copyright 2012 by Fen Logic Ltd All rights reserved Contents OVELVIE Wasior 4 Labels on the circuit 5 Location of the building blocks on the Gertboard 20 7 JUMPELS AN M 8 DINS 8 PC m 9 Test programs OVerVIeW o em ea rep 9 ned d E b npe in eo ed ID re eite iit 10 Buffered LEDs and pushbuttons esses eene enne enne 11 Push Buttons EE 12 Locating the relevant sections of the Gertboard 12 Testing the pushbU ttons teat 14 Testing the eer eee nnde 16 8 me 18 O
29. J van Loo Fen Logic Ltd Fig 23 wiring diagram for an alternative method of testing the A D and D A converters together without the aid of a multimeter and potentiometer 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 ATmega device The Gertboard can hold an Atmel AVR microcontroller a 28 pin ATmega device at location U8 on the lower left of the board This can be any of the following ATmega48A PA 88A PA 168A PA or 328 P in a 28 pin DIP package The device has a 12MHz ceramic resonator attached to pins 9 and 10 All input output pins are brought out to header J25 on the left edge of the board There is a separate 6 pin header J23 on the left side of the board that can be used to program the device The PDO PD1 pins ATmega UART TX and RX are brought out to pins placed adjacent to the Raspberry Pi UART pins so you only need to place two jumpers to connect the two devices Note that the ATmega device on the Gertboard operates at 3 3 Volts That is in contrast to t
30. LK is the clock MOSI is the output from the and MISO is the input to the 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 Both A D and D A chips have a 10K pull up resistor on their chip select pins so the devices will not be accessed if the chips select pins are not connected The SPI pins are conveniently located just above GP7 to GP11 in header J2 because one of the alternate functions of these pins is to drive the SPI signals For example the ALTO alternative 0 function of GPIO9 is SPIO_MISO which is why the pin labelled MISO is just about the pin labelled GP9 Thus to use the A D and D A simply put jumpers connecting pins GP7 to GP11 to the SPI pins directly about them although technically you only need CSnA for the A D and CSnB for the D A In the schematics the D A and A D converts are on page A 6 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 These chips are all pin compatible and are written to in the same way In particular the routine that writes to the D A assum
31. aders on the right edge of the board and the pins corresponding to are the RLY1 to RLY6 pins in the headers J12 to J17 How these are then used is demonstrated by the test wiring and code examples Testing the open collector drivers The program oco1 for open collector allows the functional testing of the open collector drivers simple mechanism was required to switch the driver on and off so we created a little circuit see diagram below consisting of two large LEDs and a resistor in series Once connected the forward voltage across each of these LEDs is a little above so we used a battery as a power supply and calculated a series resistance of around about 900 to set a suitable current flow through the LEDs Since this small test circuit will not be used again it can simply be hand soldered together off board 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 To turn the circuit off and on using the open collector driver say you want to use driver 1 first check that it works with the power supply described above Then leave the positive side of your circuit attached to the positive terminal of the power supply but in addition connect it to o
32. al to be input from the board The value of the switch from port 3 is also read in and these two should be the same most of the time In butled c we use INP_GPIO to set GPIO22 and GPIO23 to input and GPIO PULL and GPIO PULLCLKO to set the pull up on GPIO23 This is described in more detail on page 16 in the buttons test Then the GPIO values are repeatedly read in and the binary values of GPIO22 and GPIO23 are printed out if they have changed since the last cycle So if 01 is displayed on the monitor it can be deduced that GPIO23 is low and GPIO22 is high Note that the LED for port 6 labelled D6 should be off when switch 3 is pressed and on when switch 3 is up Now if the values for GPIO22 and GPIO23 are always the same 00 and 11 will only ever be printed out But if the test is started with button 3 up so 11 is displayed and then the button is pushed down occasionally 017 might be seen followed very quickly by 00 The reason for this differs between the Python and C implementations In the C version both values are read at the same time and the signal from the push button which is connected to GPIO23 takes a small amount of time to propagate through the buffers to get to GPIO22 It may even be possible to get one reading in after GPIO23 has changed but insufficient time has passed for GPIO22 to change state and follow it In the Python code the read of GPIO22 occurs before the read of GPIO23 the bu
33. arch 2012 Developed by G J van Loo H Fig 27 Wiring diagram showing the additional strap necessary for button operation for the sketch Button When you have done this the first LED will be on when the third button is pressed and off when the third button is up Now let s try using an analogue pin Find the AnalogInput sketch under File gt Examples gt Analog in both versions 0018 and 1 0 1 This reads in a value from analogue input 0 which has already been converted by the internal A D to a value between 0 and 1023 then uses that number as a delay between turning an LED on and off Thus the lower the voltage on the analogue pin the faster the LED flashes To run this example you ll need a potentiometer The one used to test the A D will work fine here The comments for AnalogInput say to connect the potentiometer so that the wiper is on analogue pin 0 PCO on the Gertboard and the outer pins are connected to 5V and ground As above you must use 3 3V instead of 5V as we re running the chip at 3 3V here The diagram below shows how to connect up the Gertboard to make this sketch work after it is uploaded 35 mm E Ec ie 990999 e 0006 4 Ss dd LET unm 595559555 J
34. arch 2012 m Cy TERN di HERE Fig 21 The wiring diagram required to measure the output from the D to A converter fitted to the Gertboard whilst running the test program dtoa The dtoa program first asks which channel to use and prints out the connections needed to make on Gertboard to run the program Then it calls setup io to get the GPIO ready to use then calls 2 to choose which pins to use and how to use them setup_gpio as usual _ where is the pin number is used to activate the pins This also sets them up to be used as They should however be used as SPI bus which is one of the alternative functions for these pins it is alternate 0 Thus we use SET GPIO ALT n where n is the pin number and a is the alternate number in this case O to select this alternate use of the pins Then the program sends different values to the D A and asks for real verification using the multimeter that the D A converter is generating the correct output voltage The test program for the A D is called atod 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 1 and the middle wiper part to ADO for channel 0 as shown below or ADI for channel 1 To use the SPI bus jum
35. ble above When A is low the motor will receive power making it turn one way when A is high it will not receive power The end result for the 25 duty cycle shown here is that the motor will turn one way at roughly 34 speed 1 1 MOTA 0 0 Fig 20 this example the truth table predicts that the motor will in the opposite direction at around 25 speed If on the other hand you set MOTB low as in the diagram above then when A is high the motor will receive power making it turn in the other direction and when A is low the motor will not receive power The result for the 25 duty cycle is that it will turn in the other direction at about speed Testing the motor controller The PWM is controlled by a memory map like the GPIO and SPI bus This memory map is part of the setup io function in so that is whether the PWM is used or not Further setup code is found in gb with an associated header file pwm h The function setup in gb pwm c sets the speed of the PWM clock and sets the maximum value of the PWM to 1024 this is the value at which the duty cycle of the PWM will be 100 It also makes sure that the PWM 1 off The two routines set pwm0 and force_pwm0 set the value that controls the duty cycle for the PWM set pwmo0 sets the value first checking that it is between 0 and 1024 but as there are only certain points in the PWM cycle where a new value is picked up
36. by a collection of global arrays given values using an initializer The number in each of the arrays says which LEDs will 17 be turned on at that point in the pattern so pattern value is submitted sequentially to produce the changing pattern switching all the LEDs off between successive pattern values Each pattern is run through twice The first pattern lights the LEDs one at a time in sequence left to right The second pattern does the same but when it reaches the rightmost LED it then reverses direction and lights them in sequence right to left The third pattern starts at the left end and at each step switches on one more LED until they are all lit up then starting at the left it switches them off one by one until they are all off Finally the test program switches off all the LEDs and then finally calls restore_io to clean up all the LEDs to a predictable final state Testing I O Our two examples so far have only used the ports to access the pushbuttons and LEDs The next example called but led for LED will show 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 m 2 lt m c 515151515151 5 55 5 we
37. cting 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 L or GND for this The red lead needs to be connected to DAO to test the D A channel 0 which is shown below or for channel 1 Switch the multimeter on and set it to measure voltages from 0 to around 5V 26 99 9229999 95965 9 959 meeeo Geee Geee Teo x m JT NI i tages LOE ee 1298 a lt 1555 NOR m 19 J20_ BUFI2 E ejet 152 LN I 12 9000000000 B20Ulg3 B4 06000009 89 09 9 0 0 9 ELI ui E LO U3 G eg 9090000000 tme e e U5p eo e e x Een m 6 e LICK e e eve emm uuu x 9 ci5 5 z350 e 0000 ITI A 25 3720 Raspberry E RI 124 3Se 0 SAINA 55555 5555555 yo 2250 11 M
38. e side of chip 03 Ports 10 and 11 are configured for input because of the jumpers across B10 and B11 on the in side of U5 In the test programs the required connections are printed out before starting the tests The input and output jumpers are referred to in the following way U3 out B1 means that there is a jumper across the B1 pins on the out side of the U3 buffer chip So the 5 jumpers in the picture above would be referred to as U3 out B1 U3 out B2 U3 out B3 U5 in B10 and U5 in B11 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 pins B1 B2 and B3 in header J3 to pins GP25 GP24 and GP23 in header J2 respectively 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 14 4942 Va dT Dua pe 09787 _ corer 5 5 99595565 MA Fig 11 Whilst the image above is clear it isn t very good at showing exactly how the straps are connected and between which pins on the board 19 F1 Fuse max 4A Eeee _ NI
39. e for this is in potmot c Functions from gb_spi c and gb are used to control the SPI bus for reading the A D and the pulse width modulator for controlling the speed of the motor To wire up the Gertboard for this example you combine the wiring for the A D and motor tests Jumpers connect GP8 to GP11 to the pins directly above them to allow us to control the SPI bus using GPIO8 to GPIO11 You must attach your potentiometer to the ADO input GPIO17 controls the motor B input and 18 controls the motor input using the pulse width modulator Thus GP17 must be connected via a strap to MOTB and GP18 must be connected to MOTA The motor and its power source must be connected to the screw terminals in J19 at the top of the board See the wiring diagram below your power source 0900 45539 mesto GND 2 8 2029 96906096 00000 liu EEko yl Ea ad Me ET eim em ejm wie SE S Raspberry Pi 1 0 extension March 2012 0000000000008 e 9 2029929359328 Developed by G J van Loo Fen Logic Ltd i V Fig 30 Wiring diagram for the combined potmot test 38 In the main routine for first we print to the terminal the connections tha
40. es 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 25 The analogue outputs of the two channels go to pins labelled DAO for channel 0 and 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 ADO 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 Since the D A and A D converters both use the SPI bus the common SPI bus code has been placed into a separate file gb_spi c There is also an associated header file gb_spi h which contains many macros and constants needed for interacting with the SPI bus as well as the declarations for the functions in gb spi These functions are setup spi read write dac setup spi sets the clock speed for the bus and clears status bits read_adc takes an argument specifying the channel should be 0 or 1 and returns an
41. from working properly To make clear what state each button is in the output jumper can be installed and then the LED will now show the button state LED on means button up LED off means button down To use the push buttons a pull up must be set on the Raspberry Pi GPIO pins used described below page 16 so that they are read as high logical 1 when the buttons are not pressed Locating the relevant sections of the Gertboard In the building blocks location diagram on page 7 the components implementing the buffered I O are outlined in red The ICs containing the buffers U3 U4 and 05 near the centre of the board The LEDs the round translucent red plastic devices are labelled D1 to D12 D1 is driven by port 1 D2 by port 2 etc The pushbutton switches the silver rectangular devices with circular depressions in the middle are labelled S1 to S3 S1 is connected to port 1 and so on The long thin yellow components with multiple pins are resistor arrays 12 The pins corresponding to Raspi in the circuit diagrams above are to B12 the J3 header above the words Raspberry Pi on the board to correspond to the Raspi points on the second circuit diagram with the pushbutton and B4 to B12 correspond to the Raspi points on the first circuit diagram They are called Raspi because these are the ones that should be connected to the pins in header J2 which are directly connected to the pins in J1 and whic
42. gh or low per the table 3 above To control the speed of the motor however pulse width modulation PWM is required This is a device that outputs a square wave that flips back and forth from on to off very rapidly as in the diagram below 0111 17 example of PWM output In this example the output is neither on nor off all the time In fact here it is on for 50 of the time and is therefore said to have a duty cycle of 50 22 With PWM you can control the amount of time the output is high vs when it is low This is called the duty cycle and is expressed as a percentage The diagram above shows a 50 duty cycle the one below is 25 1 0 Fig 18 In this PWM example the duty cycle is 25 There is a PWM in the BCM2835 the Raspberry Pi processor and it s output can be accessed via GPIO18 it is alternate function 5 If this is connected to one of the motor controller inputs MOTA has been used in our motor test and set the other motor controller input MOTB in our test to a steady high or low the speed and direction of the motor can be controlled 1 1 MOTA 0 0 19 The motor direction is set by MOTB Whilst MOTA has a duty cycle of 25 motor only receives power when MOTA and MOTB are different thus it receives power for 75 of the time For example in the diagram above we are alternating between A low B high and A high B high the second and fourth lines of the ta
43. ght way up Test programs overview When you download the Gertboard test example code available at www element14 com raspberrypi you will have a file with a name something like gertboard sw 10 07 12 tar gz Thisisa compressed hence the gz suffix which means it was compressed using the gzip algorithm archive hence the tar where an archive is a collection of different files all stored in a single file To retrieve the original software put the file where you want your Gertboard software to end up on your Raspberry Pi computer then uncompress it by typing the following in one of the terminal windows on your Pi substituting the name of the actual file you have downloaded for the file name we are using in this example gunzip gertboard sw 10 07 12 tar gz Typing a directory command 1s should then show newly uncompressed archive file gertboard_sw_10_07_12 tar So now to extract the files from the archive type tar xvf gertboard sw 10 07 12 tar A new directory gertboard sw will be created In it is a set of C files and a makefile C files are software files but they need to be compiled to run on the processor on your system In the case of Raspberry Pi this is an 11 To compile all the code to run on Raspberry Pi first change directory to gertboard sw by typing cd gertboard sw And then in that directory type make all Each building block has at least one test program that goes with it Currently the tes
44. h are then finally connected via the ribbon cable to the Raspberry Pi The pins corresponding to the point on the right of the circuit diagrams above are BUF1 to BUF12 in the unlabeled single row header at the top of the Gertboard On the Gertboard schematic I O buffers are on page A 2 The buffer chips 03 04 and 05 are clearly labelled It should be apparent that ports 1 to 4 are handled by chip U3 ports 5 to 8 by chip U4 and ports 9 to 12 by chip 05 The Raspi points in the circuit diagrams above are shown as the signals 1 to BUF 12 on the left side of the page and the I O points are BUF1 to BUFI2 to the right of the buffer chips The input jumper locations are the blue rectangles labelled P1 P3 P5 P7 etc to the left of the buffer chips and the output jumper locations are the blue rectangles labelled P2 P4 P6 P8 etc to the right of the buffer chips The pushbutton switches S1 S2 and 53 are shown separately on the right side of the page near the bottom The buffered I O ports can be used with almost any of the GPIO pins they just have to be connected up using the straps So for example if you want to use port 1 with GPIOI7 a strap is placed between the B1 pin in J3 and the GP17 pin in J2 Beware that the push buttons cannot be used with GPIOO or and in header 12 on the board as those two pins have 18000 pull up resistor the Raspberry Pi When the button is pressed the vo
45. he Arduino system which runs at 5V It is also the reason why the device does not have a 16MHz clock In fact at 3V3 the maximum operating frequency according to the specification is just under 12MHz Warning 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 The ATmega device is in the schematics on page A 6 29 Programming ATmega Programming the ATmega microcontroller is straightforward once you have all the infrastructure set up but it requires a fair bit of software to be installed on your Raspberry Pi We are immensely grateful to Gordon Henderson of Drogon Systems for working out what needed to be done and providing the customized software Using his system you can use the Arduino IDE Integrated Development Environment on the Raspberry Pi to develop and upload code for the ATmega chip on the Gertboard The Atmel chips most commonly used on the Gertboard are the 168 and ATmega328 so Gordon assumes you have one of these To use Gordon s system first you need to install the Arduino IDE Then you download a custom version of avrdude which allows you to program the AVR microcontroller using the SPI bus GPIO pins GPIO7 through GPIO11 can be used as a SPI bus Then you have to edit various configuration files to fully integrate the Gertboard
46. hed from pin 13 to ground pushbutton attached to pin 2 from 5V 10K resistor attached to pin 2 from ground Assuming that you have Blink working your LED is already wired up but what about the button As mentioned above since the ATmega chip on the Gertboard runs at 3 3V we must replace the 5V with 3 3V So they suggest using a circuit like the one below where the value read at pin 2 is logical 0 if the button is not pressed due to the 10K pull down resistor and logical 1 if the button is pressed pin 2 S 10K 3 3V O GND Fig 25 Suggested switch circuit for use with Button sketch However the buttons on the Gertboard are used like this 33 LL 1K pull up 0 3 3V Raspi Fig 26 Circuit actually in use on the Gertboard showing an additional 1k resistor to protect the input to BCM2835 The 1K resistor between the pushbutton and the Raspi point is to protect the BCM2835 the processor on the Raspberry Pi if you accidentally set the GPIO pin connected to Raspi to output instead of input The circuit to the right of the Raspi point happens on the Raspberry to use the push button we set a pull up shown as a resistor in the circuit above on the pin so that the value read is logical 1 when the button is not pressed see page 16 The Gertboard buttons are connected directly to ground so they cannot be made to read logic 1 when pressed If you are want to use a Gertboard button with
47. is required that the pin is used for an output OUT GPIO n must be called after _ Buffered 1 0 LEDs and pushbuttons There are 12 pins which can be used as input or output ports Each can be set to behave either as an input or an output using a jumper Note that the terms input and output here are always with respect to the Raspberry Pi in input mode the pin inputs data to the Pi in output mode it acts as output from the Pi It is important to keep this in mind as the Gertboard is set up an output from the Gertboard is an input to the Raspberry Pi and so the input jumper must be installed to implement this Raspi input 74 244 1 output 1k 10k x x 1k Fig 8 The circuit diagram for I O ports 4 12 The triangles symbols in the diagram above represent buffers In order to make the port function as an input to the Raspberry Pi you install the input jumper then the data flows from the I O point to the Raspi point To make the port function as an output the output jumper must be installed then the data flows from the Raspi point to the I O point If both jumpers are installed it won t harm the board but the port won t do anything sensible In both the input and output mode the LED will indicate what the logic level is on the I O pin The LED will be on when the level is high and it will be off when the level is low There is a third option
48. l pin or PCO an analogue pin depends on the context The command value digitalRead 0 will cause a read from digital 0 PDO and value will be assigned LOW or HIGH while the command value analogRead 0 will cause a read from analogue 0 PCO and value will be assigned a number between 0 and 1023 as the A D converters in the ATmega chip return 10 bit values In version 1 0 1 however although numbers 0 through 5 still work to specify analogue pins they are referred to in the examples as 0 to A5 and this seems to be the preferred style now So to read from analogue pin 0 you would use the command value analogRead A0 A few sketches to get you going A good first sketch to try is Blink which makes an LED turn on and off With version 0018 of the IDE it s in the File gt Examples gt Digital menu in 1 0 1 it s in the File gt Examples gt Basics menu When you select this a new window pops up with the Blink code There are only two functions in the code setup and 1oop These are required for all Arduino programs setup is executed once at the very beginning and 1 is called repeatedly as long as the chip has power Note that you do not need to provide any code to call these functions 31 The modified avrdude that you downloaded uses the SPI bus to upload the code to the ATmega chip so you need to connect the GPIO pins used for the SPI bus to the 6 pin header J23 as in the diagram below Here you are si
49. ltage on the input will be 10000 Xo A d 10000 18000 1 2V This is not an I O voltage which be reliably seen low The output and input jumper locations are above and below the U3 U4 and 05 buffer chips The input jumpers need to be placed on the headers below the chips shown on the board with the in text they are separated from the chip they go with by a yellow resistor array and the output jumpers need to be placed on the headers above the chips with the text If viewed closely it is clearer on the bare board it is possible to see that each row of 8 header pins above and below the buffer chips is divided up into 4 pairs of pins The pairs on U3 are labelled B1 to B4 the ones on U4 are B5 to B8 and the ones on U5 B9 to B12 The pins are for port 1 B2 for port 2 etc To use port n as an input but not when using the pushbutton if n is 1 2 or 3 a jumper is installed over the pair of pins in in the row marked in below the appropriate buffer chip To use port as an output a jumper is installed over the pair of pins in in the row marked above the appropriate buffer chip 13 Fig 10 Example of port configuration where ports 1 to 3 are set to be outputs and ports 10 and 11 are set to be inputs As concrete example in the picture above ports 1 2 and 3 are configured for output because of the jumpers across B1 B2 and B3 on th
50. m m Be x 1 0 extension 11 March 2012 2 3v3 Fig 2 A photograph of the unpopulated Gertboard viewed from above showing the silver coloured holes and pads that eventually will be home to the components as well as the legends printed in white epoxy ink and green solder resist coating o 2 co gp ID dt d uu 5158518515181518181813158181 9 om ej x WI Bi TP mo sms 8929225 0000000000 m leceeee s 5000000099 2 3 4 LN ooo E E2 1 6 me me m e m oE o Eel 2 a 2 a EXT 1 0 extension 11 2012 6 e 3v3 Fen Logic Ltd 000000 Developed by 6 1 van Loo ge Hoo00000000000 nm Fig 3 This image is a diagrammatic representation of the same photograph shown in Fig 2 above It was generated from the same files that were used to create the physical printed circuit board The blue elements in the diagram correspond to the white text and lines on the photo and the red elements correspond to the silver pads and holes on the photo From now onwards
51. mply connecting the SPI pins in the GPIO to the corresponding SPI pins in the header The arrangement of the pins in J23 is shown in the schematics on page A 6 2 lt GND gere XE FT Fuse max 4A 2 52 9 996060 eee teen 1 12 sl EEO HO EE oE oje Bi 0000000000 E EO Ho mm ome GND 512522152 20222242 mle v7 2000000000 lt e Raspberry Pi 1 0 extension 11 March 2012 B Fig 23 The wiring diagram for downloading sketches to the ATmega microprocessor To upload your sketch to the chip in Arduino IDE version 0018 either choose File gt Upload to I O Board option or click the icon with the right pointing arrow and the array of dots With version 1 0 1 choose File gt Upload Using Programmer It will take a bit of time to compile and upload and then your sketch is running But nothing is happening On most Arduino boards pin 13 the digital pin used by this sketch has an LED attached to it but not the Gertboard You have to wire up the LED yourself Looking at the table above we see that digital pin 13 is labelled 5 on the Gertboard so you need to connect PBS to one of the I O ports Looking back to the port diagram on page Error Bookmark not defined we need to connect it
52. ne of the RPWR pins in the headers on the right edge of the board they are all connected together 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 Attach the ground terminal of the power supply to any GND or L pin on the board Now we need a signal to control the driver For oco1 test 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 To test a different driver say n with the 1 test connect the ground side of the circuit up to in the headers on the right of the board and connect GP4 in header J2 to RLYn in 14 Now when RLYI1 in 14 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 20 o lt m d 5 x 5 iMseseseseseseseseseseses 0 ee e 9 RN2 19 000 0000 ys 0000 Fuse max 4A GND 03 5 5 5 07 08 y evel
53. of macros that give a more intuitive name to various parts of the arrays that have been mapped These macros are used to do everything from setting whether a GPIO is used as input or output to controlling the clock speed of the pulse width modulator In the chart below is a summary of the purpose of the more commonly used macros and give the page number on which its use is explained in more detail The T column below gives the type of the macro This shows how the macro is used means that the command is executed as in INP GPIO 17 W means that that the command is written to assigned as in GPIO PULL 2 10 means that that the command is read from as in data GPIO INO Macro name T Explanation Page no INP GPIO n E activates GPIO pin number n for input 11 OUT GPIO n E used after above sets pin n for output 11 SET GPIO E used after select alternate function for pin 24 PULL W set pull code 16 GPIO PULLCCLKO W select which pins pull code is applied to 16 GPIO INO R get input values 16 GPIO SETO W select which pins are set high 17 GPIO CLRO W select which pins are set low 17 Table 2 Commonly used macros their purpose type and location within this manual The macro INP_GPIO n must be called for a pin number n to allow this pin to be used By default its mode is set up as an input If it
54. pen Collector Diver 19 Testing the open collector 20 Motor Controller n Ehre e Ie tetti i te aet EU e ees Lede hs e ete bud 22 Testing the Motor controller gabe pa etra dete og e ba ub gs 23 Digital to Analogue and Analogue to Digital Converters esee eene 25 Digital to analogue converter ios ene cds on eer reda edili e on e erede EE 25 Analogue to Digital converter d deno bene DE De ee ete Pec eth ou 26 Testing SERES Ro 26 PLT me Ga E 29 Programming th A sed ane a erret n Ve eee pea deb ou ae 30 Arduino pins on the Gertboa rd ient 30 A tew sketches 10 Set YOU GOING rta bte eaa p rab dong 31 HT 36 Combined eoe e ee efe 38 A D Eee re C Ha pa etra dete dee Rab ra apt 38 ES 39 More Information oie EXPE 40 Appendix A css id ER e e RR RE RE RE EROR Pec 40 Gertboard Overview Raspi a mmia S o o MCP4802 MCP3002 open collector 6x
55. pers should be installed on the pins GP11 GP10 GP9 and GP8 connecting them to the SPI bus pins above them 27 o o 2 um geese Ngeee 0000 90900505008 E50 noon B B20Ul punte Mule mo mm ome 89 999 99 9 CELER cres L 15 C16 e Raspberry Pi 1 0 extension 11 March 2012 e 3v3 Hoo00000000000 mm Fen Logic Ltd Developed by G J van Loo Hs Fig 22 Wiring diagram showing how the Gertboard is connected to verify that the A D converter is working properly using the test program atod The atod program first asks which channel should be used and prints out the connections required on Gertboard to run the program Then it calls setup io to get the GPIO ready then calls setup gpio to choose which pins will be used and how they will be used The setup gpio used in atod works the same way as the one in dtoa except for activating GPIOS instead of GPIO7 Then atod repeatedly reads 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 string of characters One thing to be aware of is that even if the potentiometer is no
56. rd over GPIO The easiest way to retrieve this data is to use the minicom program You can install this easily by typing into a terminal this command sudo apt get install minicom You can use menus to configure minicom by typing minicom s Alternatively included with the Gertboard software is a file minirc ama0 with the settings you need to read from the GPIO UART pins at 9600 baud Copy this file which was provided by Gordon Henderson to etc minicom you ll probably need to sudo this and invoke minicom by typing sudo minicom Now if you upload the sketch to the ATmega chip you should see the value from the potentiometer displayed in your minicom monitor These examples have only just scratched the surface of the wonderful world of Arduino Check out http arduino cc en Tutorial HomePage for much much more 37 Combined Tests This section shows some examples of using more than one building block at a time A D and motor controller In the potmot for potentiometer motor test we use a potentiometer connected to the analogue to digital converter A D to get an input value and this value is used to control the speed and direction of the motor It is set up so that at one extreme the motor is going at top speed and as you move the wiper towards the middle it slows at the middle the motor stops and as you continue to move the wiper along the motor speeds up again but in the other direction The main routin
57. re in header J3 GP25 to B1 GP24 to B2 GP23 to B3 GP22 to B4 GP21 to B5 GP18 to B6 17 to B7 to B8 GP10 to B9 9 to B10 GP8 to B11 and GP7 to B12 In other words the leftmost 12 GP pins are connected to the pins except that GP14 and 5 missed out they are already set to UART mode by Linux so it s best if they are not touched If there aren t enough jumpers or straps to wire these connections all up at once don t worry Just wire up as many as possible and run the test Once it s finished the straps jumpers can be moved and the test can be run again Nothing bad will happen if a pin is written to that has nothing connected to it 16 Sesso aesso s 390020000096 747747 2 0 6 60 6 ET 0000000000 i c9 Bi B20Utp3 u 21009090 6 5 300000000 222222227 088160659905 NN Raspberry Pi 1 0 extension 11 March 2012 e 6 3 3 Developed by G J van Loo Fen Logic Ltd H co Fig 13 The wiring diagram necessary to run the Gertboard LED test program leds The test code in 1eds c first calls setup io to get everything ready Then setup gpio is called which prepares 12 GPIO pins to be used as outputs as all 12 I O ports will require controlling of the GPIO signals except GPIO 0 1
58. rminal of the power supply dropping quickly afterwards The chip itself has an internal diode connecting the RLYn pin to the RPWR This allows current to flow to the top positive side of your circuit allowing the energy to dissipate and preventing damage The 1 test is very simple First it prints out the connections required on the board and with your external circuit and power supply and then it calls setup_io to get the GPIO interface ready to use and setup gpio to set pin GPIO4 to be used as an output using the commands 4 OUT GPIO 4 as described on page 11 Then in it uses GPIO_SETO and GPTO_CLRO described on page 17 to set GPIO4 high then low 10 times Note the test asks which driver should be tested but it only uses this information to print out the connections that need to be made Otherwise it ignores your response 21 Motor Controller The Gertboard has a position for a L6203 Miniwatt package motor controller The motor controller is 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 A B Motor action 0 0 no movement 0 1 rotate one way 1 0 rotate opposite way from above 1 1 no movement Table 3 Truth
59. t 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 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 ADO as in the diagram below 28 m a 8 2 13 34 41841 41313134184841 ES 19 SML les 9 H 5 90000 da NN NIS 230 0 e e 3 0000000000 U6 ______ e C9 BI e s we 92222247 000000000 L us xi eim eim E 06999999 5 PIPININ Mae ee ene eess mmm lt 3 ci5 on F1 Fuse max 4A O i gt e e Raspberry Pi 1 0 extension 11 March 2012 Developed by G
60. t need to be made on the Gertboard to run this example then we call setup_io to set up the GPIO ready for use Then we call setup_gpio to set the GPIO pins the way we want them In this we set up GPIO8 to GPIO11 to use the SPI bus using _ and SET_GPIO_ALT as described in the section on A D and D A converters page 27 GPIO17 is set up as an output using INP_GPIO and OUT GPIO and GPIO18 is set up as a PWM using as _ and SET_GPIO_ALT as described in the section on the motor controller page 24 Back in main we call setup_spi and setup pwm to get the SPI bus and PWM ready for use and get the motor ready to go Then we repeatedly read the A D and set the direction and speed of the motor depending on the value we read Lower A D values up to 511 recall that the A D chip used returns a 10 bit value so the maximum will be 1023 result in the motor B input being set high and thus the motor goes in the rotate one way as in the motor controller table on page 22 Confusingly this motor direction is called backwards in the comments of the program Higher A D values 512 to 1023 result in the motor B input being set low and the motor goes in the rotate opposite way direction This is called forwards in the comments of the program Simple arithmetic is used to translate A D values near 511 to slow motor speeds and A D values near the endpoints of the range 0 and 1023 to
61. t programs These are shown in the table below The rest are only used as general purpose input output in the code On page 27 there is a description of how to gain access to the alternate functions of GPIO pins GPIOO SDAO alt 0 bus SLCO alt 0 GPIO7 SPI_CE1_N alt 0 GPIO8 SPI CEO N alt 0 GPIO9 SPI MISO alt 0 SPI bus 10 SPI alt 0 GPIO11 SPI SCLK alt 0 14 TXDO alt 0 15 RXDO alt 0 TORI GPIO18 PWMO alt 5 pulse width modulation Table 1 Table showing the GPIO pins on the Gertboard and what their alternative function is We mention the bus use GPIOO and 1 above not because the bus is used in the test programs but because each of them has a 18000 pull up resistor on the Raspberry Pi and this prevents them from being used with the pushbuttons see page 134 Schematics Whilst there are some circuit diagrams or schematics in the main body of the manual for some of the building blocks of the board they are simplifications of the actual circuits on the board To truly understand the board and the connections you need to make on it you need to be a little familiar with the schematics Thus we have attached the full schematics at the end of this manual as Appendix A These pages are in landscape format The page numbers A 1 A 2 etc are in the lower left corner of the pages if you hold them so that the writing is the ri
62. t programs are written in C but they ll be translated into Python in the near future Each test program is compiled from two or more C files The file gb common which has an associated header file gb common h contains code used by all of the building blocks on the board Each test has a C file that contains code specific to that test thus you will find main here Some of the tests use a special interface for example the SPI bus and these tests have an additional C file that provides code specific to that interface these files are gb spi c for the SPI bus and gb for the pulse width modulator In each of the sections about the individual building blocks the code specific to the tests for that block is explained Since all of the tests share the code in gb common c an overview of that code will be given here In order to use the Gertboard via the GPIO the test code first needs to call setup io This function allocates various arrays and then calls to associate the arrays with the devices that it wants to control such as the GPIO SPI bus PWM pulse width modulator etc The result of this is that it writes to these arrays control the devices or sends data to them and reads from these arrays get status bits or data from the devices At the end of a test program restore io should be called which undoes the memory map and frees the allocated memory Macros In gb common h gb spi h and gb pwm h there are a number
63. tton Thus if the button is pressed or released between these two reads the new value will be read in for the button GPIO23 but the new value of the other input GPIO22 won t change until the next time through the while loop Open Collector Driver The Gertboard uses six ports of a ULN2803a 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 Each driver has an integrated protection diode the uppermost diode in the circuit diagram below common OUT Raspi Fig 15 Circuit diagram of each open collector driver 19 The common is as the name states common for all open collector drivers It is not connected to any other point on the Gertboard As with all devices the control for the open collector drivers the Raspi point can also be connected to the ATmega controller to for example drive relays or motors The open collector drivers are in the schematics on page 3 On the Gertboard building block diagram on page 7 the area containing the components for the open collector drivers are outlined in yellow The pins corresponding to Raspi in the diagram above are RLY1 to RLY6 pins in the J4 header the pins corresponding to common the ones marked RPWR in the he
64. y instructions do not require that a header is installed to access this If 5V is really required and spare header pins are available a header can be soldered in location J24 in the lower right hand corner of the board and then a 5V supply be picked up from the lower pin next to the text SV Ground is marked with GND or a L symbol Location of the building blocks on the Gertboard aren a Raspberry Pi extension UB March 2012 5 __ buffered I O switches and LEDs 1 Atmel ATmega chip 1 open collector driver GPIO pins motor controller A to D and D to A converters Fig 5 Photograph of an assembled Gertboard with key functional blocks identified by coloured boundary marking This image serves as a good reference point for a board that has been successfully assembled from bare board and components Please note that the appearance of some components can vary This annotated photo of a populated Gertboard shows where the building blocks the major capabilities of the board are located Some of the building blocks have two areas marked For example the turquoise lines showing the Atmel ATmega chip not only surround the chip itself on the lower left but also surround two header pins near the bottom of the board in the middle These pins are connected to the Atmel chip and provide an easy way to interface the GPIO signals from the Raspberry Pi which are in the black box with the
Download Pdf Manuals
Related Search
Related Contents
本書の内容 - 自動車公論社 Steba KB 23 Integuseal, pellicule bactério-isolante du site - Euro Unified Requirements of DVB-C and DVB-T2 Tecumseh AJA9484EXD Drawing Data Bedienungsanleitung U-30-6 - 株式会社クボタ 建設機械事業部 INCIDENT 11 octobre 2005 - avion immatriculé F-GBMZ TOWER-20 PG2 Detector de Movimentos PIR de Espelho para Copyright © All rights reserved.
Failed to retrieve file