CUSTARD PI 2General Purpose I/O for the Raspberry Pi2nd June 2013SF Innovations
FEATURESwww.sf-innovations.co.uk
DIGITAL OUTPUTSwww.sf-innovations.co.uk4 digital outputsOpen collector – can sink 500 mA when lowOutput can be taken up to...
SAMPLE PYTHON CODE TO TEST DIGITALOUTPUTSwww.sf-innovations.co.uk#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGP...
DIGITAL INPUTSwww.sf-innovations.co.uk4 digital inputsPull down externally for lowAccept any voltage up to 20V for highUse...
www.sf-innovations.co.ukSAMPLE PYTHON CODE TO TEST DIGITALINPUTS#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGPI...
ANALOGUE OUTPUTSwww.sf-innovations.co.uk2 (12 bit) analogue output channels using 2 channel D to A ICFull scale voltage (w...
www.sf-innovations.co.uk#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGPIO.setmode(GPIO.BOARD)GPIO.setup(26, GPIO...
www.sf-innovations.co.ukGPIO.output(26, True)time.sleep(5)GPIO.output(26, False)for x in range (0,16):GPIO.output(19, word...
ANALOGUE INPUTSwww.sf-innovations.co.uk2 (12 bit) analogue input channels using 2 channel A to D ICMaximum input 3.3V will...
www.sf-innovations.co.ukSAMPLE PYTHON CODE TO TEST ANALOGUEINPUTS#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGP...
www.sf-innovations.co.ukfor x in range (0,12):GPIO.output(23,True)time.sleep(0.01)bit=GPIO.input(21)time.sleep(0.01)GPIO.o...
FURTHER INFORMATIONwww.sf-innovations.co.ukBlog dedicated to electronics & Raspberry PiCustard Pi 2 available from Amazon....
Upcoming SlideShare
Loading in …5
×

Custard Pi 2 - Analogue and digital I/O for the Raspberry Pi

5,086 views

Published on

The Custard Pi 2 provides the following benefits for the hobbyist intending to use the GPIO.
1. Provision of the following I/O.

4 open-collector digital outputs
4 buffered digital inputs
2 x 12 bit analogue outputs
2 x 12 bit analogue inputs

2 The board simply plugs into the 26 way GPIO connector. Two power on LEDs are fitted to the 3.3V and 5V rails to confirm correct plug in.

3. All the pins on the Pi are protected from accidental connection of a high voltage.

4. There are screw terminals provided for easy connection to external electronics: 4 digital outputs, 4 digital inputs, 2 analogue outputs, 2 analogue inputs and power.

5. There are no screw terminal connection to the 6 pins that are not in use. This prevents accidental connection to them.

6. The 3.3 V and 5 V voltage rails have 100 mA multifuses fitted and are protected from over voltage.

Published in: Technology
2 Comments
1 Like
Statistics
Notes
  • How would you use a DS18B20 temp sensor with the digital inputs? Using a custard pi2 but cant seem to be able to access it. I can access and read it when I connect directly to the rpi gpio pins. More tutorials with the custard pi range would be really helpful. Cheers.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • On slide 10, you say pin 20 is data in, and 21 is data out, then on slide 11, you set pin21 as input. On slide 12, you claim channel 0 should read 3.3V when you put the 3.3V supply through it, but this reads 0, channel 1 reads 3.3V. How would I go about using channel 0 at the same time? i can't find any documentation at all on this matter.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
5,086
On SlideShare
0
From Embeds
0
Number of Embeds
196
Actions
Shares
0
Downloads
0
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Custard Pi 2 - Analogue and digital I/O for the Raspberry Pi

  1. 1. CUSTARD PI 2General Purpose I/O for the Raspberry Pi2nd June 2013SF Innovations
  2. 2. FEATURESwww.sf-innovations.co.uk
  3. 3. DIGITAL OUTPUTSwww.sf-innovations.co.uk4 digital outputsOpen collector – can sink 500 mA when lowOutput can be taken up to 50V
  4. 4. SAMPLE PYTHON CODE TO TEST DIGITALOUTPUTSwww.sf-innovations.co.uk#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGPIO.setmode(GPIO.BOARD)GPIO.setup(11, GPIO.OUT)GPIO.setup(12, GPIO.OUT)GPIO.setup(13, GPIO.OUT)GPIO.setup(15, GPIO.OUT)for x in range (0,20):GPIO.output(11, True)GPIO.output(12, True)GPIO.output(13, True)GPIO.output(15, True)time.sleep(0.2)GPIO.output(11, False)GPIO.output(12, False)GPIO.output(13, False)GPIO.output(15, False)time.sleep(0.2)GPIO.cleanup()import syssys.exit()This program sets pins 11, 12, 13 & 15 as outputs.Sets them all highWaits 0.2 secondsSets them all lowWaits 0.2 secondsRepeats 20 timesConnect an led to 3.3V, 5V or any voltage up to 50VConnect a resistor in series (say 1 kohm) tolimit the currentConnect the other side of the resistor toPins 11, 12, 13 or 15 to see it flash.Note: When GPIO pin is taken high, the outputon the Custard Pi goes low (i.e. it is inverted).Download code
  5. 5. DIGITAL INPUTSwww.sf-innovations.co.uk4 digital inputsPull down externally for lowAccept any voltage up to 20V for highUse pull up on Raspberry Pi to detect high
  6. 6. www.sf-innovations.co.ukSAMPLE PYTHON CODE TO TEST DIGITALINPUTS#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGPIO.setmode(GPIO.BOARD)GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)for x in range (0,10):bit1=GPIO.input(7)bit2=GPIO.input(22)bit3=GPIO.input(18)bit4=GPIO.input(16)print bit1, bit2, bit3, bit4time.sleep(1)GPIO.cleanup()import syssys.exit()This program sets up pins 7,22,18 & 16As inputs with a pull up resistorScans all 4 inputsPrints results to screenWaits 1 secondRepeats 10 timesFor high, do not connect anything to pin(pull up on Raspberry Pi will keep I/P high)Revision 1 (no Custard Pi 2 legend on PCBand 4 diodes on the back of the PCB)For low link pin to 0 V (ie non-inverting inputs)Revision 2 (Custard Pi 2 legend on PCB andno diodes on the back of the PCB)For low link pin to 3.3V (ie inverting inputs)Download code
  7. 7. ANALOGUE OUTPUTSwww.sf-innovations.co.uk2 (12 bit) analogue output channels using 2 channel D to A ICFull scale voltage (when all 12 bits are High) is 2.048V
  8. 8. www.sf-innovations.co.uk#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGPIO.setmode(GPIO.BOARD)GPIO.setup(26, GPIO.OUT)GPIO.setup(23, GPIO.OUT)GPIO.setup(19, GPIO.OUT)GPIO.output(26, True)GPIO.output(23, False)GPIO.output(19, True)count = 0word1= [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]word2= [1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]while count<5:GPIO.output(26, False)for x in range (0,16):GPIO.output(19, word1[x])print word1[x]time.sleep(0.01)GPIO.output(23, True)time.sleep(0.01)GPIO.output(23, False)Program sets pins 26, 23 and 19 as outputs26 - chip enable23 – clock19 – data outWord11st bit High – writing to Channel B2nd bit Low – either state is OK3rd bit High – when all bits high, V = 2.048V4th bit High – output availableLast 12 bits all High = 4096 = 2.048VWord2Last 12 bits =011111111111= 2048 = 1.024 VChip enable (pin 26) LowClock out word1 bit by bit on pin 19Data valid when clock (pin 23) goes from L to HSet 1st bit low to output to Channel ASAMPLE PYTHON CODE TO TEST ANALOGUEOUTPUTS
  9. 9. www.sf-innovations.co.ukGPIO.output(26, True)time.sleep(5)GPIO.output(26, False)for x in range (0,16):GPIO.output(19, word2[x])print word2[x]time.sleep(0.01)GPIO.output(23, True)time.sleep(0.01)GPIO.output(23, False)GPIO.output(26, True)print countcount = count + 1time.sleep(5)GPIO.cleanup()import syssys.exit()Chip enable HighThis makes analogue voltage available (word 1)Wait 5 secondsChip enable LowClock out word2 bit by bit on pin 19Data valid when clock (pin 23) goes from L to HChip enable HighThis makes analogue voltage available (word 2)Wait 5 secondsRepeat 5 times (using variable count)Use multi-meter on channel B to see voltagecycle from 2V to 1V five times.SAMPLE PYTHON CODE TO TEST ANALOGUEOUTPUTSDownload code
  10. 10. ANALOGUE INPUTSwww.sf-innovations.co.uk2 (12 bit) analogue input channels using 2 channel A to D ICMaximum input 3.3V will set all 12 bits High
  11. 11. www.sf-innovations.co.ukSAMPLE PYTHON CODE TO TEST ANALOGUEINPUTS#1/usr/bin/env pythonimport RPi.GPIO as GPIOimport timeGPIO.setmode(GPIO.BOARD)GPIO.setup(24, GPIO.OUT)GPIO.setup(23, GPIO.OUT)GPIO.setup(19, GPIO.OUT)GPIO.setup(21, GPIO.IN)GPIO.output(24, True)GPIO.output(23, False)GPIO.output(19, True)word1= [1, 1, 1, 1, 1]GPIO.output(24, False)anip=0for x in range (0,5):GPIO.output(19, word1[x])time.sleep(0.01)GPIO.output(23, True)time.sleep(0.01)GPIO.output(23, False)Program sets pins 24, 23 and 19 as outputsPin 21 as input24 - chip enable23 – clock19 – data out21 – data inWord11st bit High – start bit2nd bit High – two separate channels3rd bit High – input on Channel 14th bit High – Most significant bit first5th bit High – Clock in null bitChip enable (pin 24) LowClock out word1 bit by bit on pin 19Data valid when clock (pin 23) goes from L to HSet 3rd bit Low to input on Channel 0
  12. 12. www.sf-innovations.co.ukfor x in range (0,12):GPIO.output(23,True)time.sleep(0.01)bit=GPIO.input(21)time.sleep(0.01)GPIO.output(23,False)value=bit*2**(12-x-1)anip=anip+valueprint x, bit, value, anipGPIO.output(24, True)volt = anip*3.3/4096print voltGPIO.cleanup()import syssys.exit()Clock in 12 bits on pin 21Data valid when clock (pin 23) goes from L to HWork out decimal value based on position & value of bitX = position of bitBit = 0 or 1Value = value of that bitanip = running totalPrint x, bit, value, anipChip enable highWork out and print voltageConnect Channel 0 to 3.3V and voltage should be 3.3VConnect two equal resistors in series from 3.3V to 0V.Connect mid point of resistors to Channel 0 inputVoltage should be 1.65VSAMPLE PYTHON CODE TO TEST ANALOGUEINPUTSDownload code
  13. 13. FURTHER INFORMATIONwww.sf-innovations.co.ukBlog dedicated to electronics & Raspberry PiCustard Pi 2 available from Amazon.co.uk and E-bayUp-to-date info on stockists on website

×