Hi!
I just purchased a PyBoard and it works great so far via the USB connection.
I also purchased a PIR sensor and am wondering now how in general to connect anything to the blank connection holes on the board? Also could not find anything about that in the documentation? The servo motor tutorial shows that servos are connected to a differently looking PyBoard with lots of female sockets on the board, that's not how the Pyboard looks that I got delivered? I'm just puzzled b/c there' no mentioning in the tutorial that that board was special in any way?
The PIR came with a connector cable but those pins are far too thin to be securely fitted to the holes on the PyBoard?
Thanks for any hints,
Michael
How to connect any external device/sensor?
-
- Posts: 4
- Joined: Fri Aug 14, 2015 11:15 pm
You can purchase the pyboard with or without headers
This is a picture of the board without headers:
https://micropython.org/store/#/products/PYBv1_0
This is a picture of it with female headers:
https://www.dropbox.com/s/n7qioq8iwk7ea ... 2.jpg?dl=0
And I also did one with male headers:
http://forum.micropython.org/viewtopic. ... oot0#p1864
How you go about connecting sensors really depends on the sensor. The micropython GPIO pins are 5v tolerant - in that they'll produce a 3.3v output but will accept upto 5v input in digital mode. For ADC mode the input is limited to 3.3v.
If you're talking about a PIR sensor like this one: https://www.sparkfun.com/products/13285 then it says it has an open collector output. What that means is the sensor will drive a signal to ground, but you need a pullup to get the signal to go high.
So you'll need to connect the sensor up to VIN and ground, and then connect input to one of the gpio pins on the micropython board. When the pyboard is powered by USB, then VIN can be used to provide power to small sensors (USB allows up to 100mA or sometimes 500mA depending on the port). When you configure the input pin, you should enable the internal pullup resistor. Here's some sample code I wrote using the USR switch as an input rather than a PIR sensor:
X17 corresponds to the USR Switch on the pyboard. So the blue LED should be on and the value should be 1 when the USR switch is not pressed, and the blue LED should go out and the value should be zero when the USR switch is pressed.
Replace X17 with the gpio pin you connect your sensor to.
This is a picture of the board without headers:
https://micropython.org/store/#/products/PYBv1_0
This is a picture of it with female headers:
https://www.dropbox.com/s/n7qioq8iwk7ea ... 2.jpg?dl=0
And I also did one with male headers:
http://forum.micropython.org/viewtopic. ... oot0#p1864
How you go about connecting sensors really depends on the sensor. The micropython GPIO pins are 5v tolerant - in that they'll produce a 3.3v output but will accept upto 5v input in digital mode. For ADC mode the input is limited to 3.3v.
If you're talking about a PIR sensor like this one: https://www.sparkfun.com/products/13285 then it says it has an open collector output. What that means is the sensor will drive a signal to ground, but you need a pullup to get the signal to go high.
So you'll need to connect the sensor up to VIN and ground, and then connect input to one of the gpio pins on the micropython board. When the pyboard is powered by USB, then VIN can be used to provide power to small sensors (USB allows up to 100mA or sometimes 500mA depending on the port). When you configure the input pin, you should enable the internal pullup resistor. Here's some sample code I wrote using the USR switch as an input rather than a PIR sensor:
Code: Select all
import pyb
sensor = pyb.Pin('X17', pyb.Pin.IN, pull=pyb.Pin.PULL_UP)
led = pyb.LED(4) # blue
prev_val = -1
while True:
curr_val = sensor.value()
if curr_val != prev_val:
print('Value is:', curr_val)
if curr_val:
led.on()
else:
led.off()
prev_val = curr_val
pyb.delay(100)
Replace X17 with the gpio pin you connect your sensor to.
-
- Posts: 4
- Joined: Fri Aug 14, 2015 11:15 pm
Re: How to connect any external device/sensor?
Thanks for your reply, that's very helpful!
So, adafruit.com the US importer of the Pyboard only seems to offer the header-less version (also good to learn those are called headers. Wondering what's the difference to 'terminals' that the other post here is mentioning).
I have this PIR: http://www.adafruit.com/product/189 and weirdly it even does not mention if it's open collector output, but how genius is it that the Pyboard has a switchable built-in pull up resistor, how convenient!
I was mostly concerned with the best physical connection between the PIR and the board as I'm not aware of all the cables, headers, terminals and what not one should use for connect things.
Couple of questions left, if you don't mind?
* Do I have to solder those headers on or is there anything plug-n-play?
* Do 'headers' hold cables I put in similar to breadboards? I have worked with breadboards in my electronics course but have no experience with connectors for PCB boards themselves. If headers do hold the cables, do I have to match the incoming cable diameter when I look which ones to buy?
Thanks a lot!
Michael
So, adafruit.com the US importer of the Pyboard only seems to offer the header-less version (also good to learn those are called headers. Wondering what's the difference to 'terminals' that the other post here is mentioning).
I have this PIR: http://www.adafruit.com/product/189 and weirdly it even does not mention if it's open collector output, but how genius is it that the Pyboard has a switchable built-in pull up resistor, how convenient!

I was mostly concerned with the best physical connection between the PIR and the board as I'm not aware of all the cables, headers, terminals and what not one should use for connect things.
Couple of questions left, if you don't mind?
* Do I have to solder those headers on or is there anything plug-n-play?
* Do 'headers' hold cables I put in similar to breadboards? I have worked with breadboards in my electronics course but have no experience with connectors for PCB boards themselves. If headers do hold the cables, do I have to match the incoming cable diameter when I look which ones to buy?
Thanks a lot!
Michael
Re: How to connect any external device/sensor?
Headers is a sort of generic term.
There are actually several different kinds of headers. This tutorial on the spark fun page covers alot of the basics.
In particular about 3/4 of the way down it talks about machine pin headers. The female header on the arduino boards are designed to mate with square pin style headers.
What I tend to do for my prototyping is that I buy jumper wires with a female connector on each end. Then I buy some extra-long header pins (often used for wire wrapping). Then I can pull individual pins from the header strip and stick it into my female connector to convert it into a male connector.
I normally solder my headers in, although I've seen these solderless headers as well:
https://www.sparkfun.com/products/10527
Ribbon cables normally use 2 x something since the headers are normally 0.1" spacing and the ribbon cable is often 0.05" spacing.
You can buy packs of jumper wires:
https://www.sparkfun.com/search/results ... mper+wires
in all sorts of arrangements (M-M, M-F, F-F, etc).
I have my own crimper, so I buy the individual pieces and crimp my own stuff when I want particular lenghts of wires, but I use the "packs" for prototyping.
You can also buy wires from Digikey (and probably other places) with the appropriate end-pieces already crimped on.
Here's some good info on how you go about doing wire crimps, but it is a fairly time consuming process.
http://sparks.gogo.co.nz/crimping/index.html
There are actually several different kinds of headers. This tutorial on the spark fun page covers alot of the basics.
In particular about 3/4 of the way down it talks about machine pin headers. The female header on the arduino boards are designed to mate with square pin style headers.
What I tend to do for my prototyping is that I buy jumper wires with a female connector on each end. Then I buy some extra-long header pins (often used for wire wrapping). Then I can pull individual pins from the header strip and stick it into my female connector to convert it into a male connector.
I normally solder my headers in, although I've seen these solderless headers as well:
https://www.sparkfun.com/products/10527
Ribbon cables normally use 2 x something since the headers are normally 0.1" spacing and the ribbon cable is often 0.05" spacing.
You can buy packs of jumper wires:
https://www.sparkfun.com/search/results ... mper+wires
in all sorts of arrangements (M-M, M-F, F-F, etc).
I have my own crimper, so I buy the individual pieces and crimp my own stuff when I want particular lenghts of wires, but I use the "packs" for prototyping.
You can also buy wires from Digikey (and probably other places) with the appropriate end-pieces already crimped on.
Here's some good info on how you go about doing wire crimps, but it is a fairly time consuming process.
http://sparks.gogo.co.nz/crimping/index.html
-
- Posts: 4
- Joined: Fri Aug 14, 2015 11:15 pm
Re: How to connect any external device/sensor?
Hey,
sorry, somehow I did not get a notification about your reply. All very useful infos, thank you very much.
I went to the local electronics shop and got myself some headers, connector cables and such and so far things are working almost perfectly. Think I should let this thread rest now and open new ones for any new questions.
Thanks again!
michael
sorry, somehow I did not get a notification about your reply. All very useful infos, thank you very much.
I went to the local electronics shop and got myself some headers, connector cables and such and so far things are working almost perfectly. Think I should let this thread rest now and open new ones for any new questions.
Thanks again!
michael