From sasithaweerasekera at rocketmail.com Fri Jul 7 22:55:58 2017 From: sasithaweerasekera at rocketmail.com (sasithaweerasekera) Date: Sat, 08 Jul 2017 08:25:58 +0530 Subject: [Microbit-Python] Microbit DHt11 temp and humidity sensor Message-ID: <413939.61754.bm@smtp212.mail.ne1.yahoo.com> Hi I want to measure and display the humidity by the microbit using microbit and the leds of the microbit, do you know the coding, because I can't find any except for bit banging which is a concept I am not familiar with, if there is a library it would help a lotThanking you in advance for ur time;Sasitha Sent from my Samsung Galaxy smartphone. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jim at groklearning.com Sat Jul 8 03:10:33 2017 From: jim at groklearning.com (Jim Mussared) Date: Sat, 8 Jul 2017 17:10:33 +1000 Subject: [Microbit-Python] Microbit DHt11 temp and humidity sensor In-Reply-To: <413939.61754.bm@smtp212.mail.ne1.yahoo.com> References: <413939.61754.bm@smtp212.mail.ne1.yahoo.com> Message-ID: Hi, The micro:bit doesn't have a humidity sensor built-in, so you'll need to use some sort of external device. I've seen a few I2C sensors, but it's also pretty common to see Dallas 1-wire used in these sorts of sensors. You'll find I2C a lot easier on the micro:bit. So if you could let us know which sensor you're using then we can give you some advice. Jim On 8 July 2017 at 12:55, sasithaweerasekera via Microbit wrote: > Hi I want to measure and display the humidity by the microbit using microbit > and the leds of the microbit, do you know the coding, because I can't find > any except for bit banging which is a concept I am not familiar with, if > there is a library it would help a lot > Thanking you in advance for ur time; > Sasitha > > > > Sent from my Samsung Galaxy smartphone. > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > From jim at groklearning.com Sat Jul 8 07:01:55 2017 From: jim at groklearning.com (Jim Mussared) Date: Sat, 8 Jul 2017 21:01:55 +1000 Subject: [Microbit-Python] Microbit DHt11 temp and humidity sensor In-Reply-To: References: <413939.61754.bm@smtp212.mail.ne1.yahoo.com> Message-ID: I just realized you had the sensor details in the subject line - DHT11. It looks a lot like a 1-wire device -- datasheet at https://cdn-shop.adafruit.com/datasheets/DHT11-chinese.pdf (and similar to https://cdn-shop.adafruit.com/datasheets/DHT22.pdf). I think you're going to have a hard time doing this from MicroPython on the micro:bit because you don't have microsecond-level timing. I recommend trying to find an I2C sensor instead - that'll be much easier to use. Or if you want to make it really easy, some sort of analog interface sensor (i.e. where you read a voltage from it). On 8 July 2017 at 17:10, Jim Mussared wrote: > Hi, > > The micro:bit doesn't have a humidity sensor built-in, so you'll need > to use some sort of external device. I've seen a few I2C sensors, but > it's also pretty common to see Dallas 1-wire used in these sorts of > sensors. You'll find I2C a lot easier on the micro:bit. > > So if you could let us know which sensor you're using then we can give > you some advice. > > Jim > > > On 8 July 2017 at 12:55, sasithaweerasekera via Microbit > wrote: >> Hi I want to measure and display the humidity by the microbit using microbit >> and the leds of the microbit, do you know the coding, because I can't find >> any except for bit banging which is a concept I am not familiar with, if >> there is a library it would help a lot >> Thanking you in advance for ur time; >> Sasitha >> >> >> >> Sent from my Samsung Galaxy smartphone. >> >> _______________________________________________ >> Microbit mailing list >> Microbit at python.org >> https://mail.python.org/mailman/listinfo/microbit >> From jim at groklearning.com Sat Jul 8 07:51:48 2017 From: jim at groklearning.com (Jim Mussared) Date: Sat, 8 Jul 2017 21:51:48 +1000 Subject: [Microbit-Python] Microbit DHt11 temp and humidity sensor In-Reply-To: References: <413939.61754.bm@smtp212.mail.ne1.yahoo.com> Message-ID: OK you piqued my interest and I remembered I had a humidity sensor in my drawer which fortunately is a (very similar) DHT22. The way the sensor works, like a 1-wire or 12C device, is both the micro:bit and the sensor share the same line which is pulled-up to 3.3V. Either device can pull it low to transmit data. To initiate a read, the micro:bit needs to pull it low momentarily, then the sensor will do it 40 times. A short pulse (!30us) is a '0' and a long pulse (70us) is a '1'. There's no way you can measure those pulses using read_digital etc on a micro:bit, but there is a very easy way to sample a pin a high speed using SPI. So we wire the temperature sensor's data line to two pins - one in SPI mode for reading, the other in digital mode to do the initial pulse. The complete wiring is GND=GND, Vcc=3V, Data=Pin0,Pin1, and a 10k resistor between data and 3V. You could use any pair of pins though instead of Pin0, Pin1. Basically the way this code works is it toggles pin1 low, then switches it back to input mode (high impedance). Then it reads at 250000 bits/s on the SPI line, which means we get approximately 4-5 bits for a '0' and 11-12 bits for a '1'. The rest of the code just unpacks this into an array of 5 bytes that contain two bytes of humidity data, two bytes of temperature, and one byte checksum. On your DHT11 it only has one byte each for the humidity and temperature, I think the changes you'll need are: temp = result[2] humidity = result[0] I used https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.cpp as a reference. Let me know if that works for you! Jim On 8 July 2017 at 21:01, Jim Mussared wrote: > I just realized you had the sensor details in the subject line - DHT11. > > It looks a lot like a 1-wire device -- datasheet at > https://cdn-shop.adafruit.com/datasheets/DHT11-chinese.pdf (and > similar to https://cdn-shop.adafruit.com/datasheets/DHT22.pdf). I > think you're going to have a hard time doing this from MicroPython on > the micro:bit because you don't have microsecond-level timing. > > I recommend trying to find an I2C sensor instead - that'll be much > easier to use. Or if you want to make it really easy, some sort of > analog interface sensor (i.e. where you read a voltage from it). > > > On 8 July 2017 at 17:10, Jim Mussared wrote: >> Hi, >> >> The micro:bit doesn't have a humidity sensor built-in, so you'll need >> to use some sort of external device. I've seen a few I2C sensors, but >> it's also pretty common to see Dallas 1-wire used in these sorts of >> sensors. You'll find I2C a lot easier on the micro:bit. >> >> So if you could let us know which sensor you're using then we can give >> you some advice. >> >> Jim >> >> >> On 8 July 2017 at 12:55, sasithaweerasekera via Microbit >> wrote: >>> Hi I want to measure and display the humidity by the microbit using microbit >>> and the leds of the microbit, do you know the coding, because I can't find >>> any except for bit banging which is a concept I am not familiar with, if >>> there is a library it would help a lot >>> Thanking you in advance for ur time; >>> Sasitha >>> >>> >>> >>> Sent from my Samsung Galaxy smartphone. >>> >>> _______________________________________________ >>> Microbit mailing list >>> Microbit at python.org >>> https://mail.python.org/mailman/listinfo/microbit >>> -------------- next part -------------- A non-text attachment was scrubbed... Name: dht22.py Type: text/x-python Size: 1276 bytes Desc: not available URL: From ntoll at ntoll.org Sat Jul 8 08:35:57 2017 From: ntoll at ntoll.org (Nicholas H.Tollervey) Date: Sat, 08 Jul 2017 13:35:57 +0100 Subject: [Microbit-Python] Microbit DHt11 temp and humidity sensor In-Reply-To: References: <413939.61754.bm@smtp212.mail.ne1.yahoo.com> Message-ID: <1499517357.2227.7.camel@ntoll.org> This is epic. :-) On Sat, 2017-07-08 at 21:51 +1000, Jim Mussared via Microbit wrote: > OK you piqued my interest and I remembered I had a humidity sensor in > my drawer which fortunately is a (very similar) DHT22. > > The way the sensor works, like a 1-wire or 12C device, is both the > micro:bit and the sensor share the same line which is pulled-up to > 3.3V. Either device can pull it low to transmit data. > > To initiate a read, the micro:bit needs to pull it low momentarily, > then the sensor will do it 40 times. A short pulse (!30us) is a '0' > and a long pulse (70us) is a '1'. > > There's no way you can measure those pulses using read_digital etc on > a micro:bit, but there is a very easy way to sample a pin a high > speed > using SPI. > > So we wire the temperature sensor's data line to two pins - one in > SPI > mode for reading, the other in digital mode to do the initial pulse. > The complete wiring is GND=GND, Vcc=3V, Data=Pin0,Pin1, and a 10k > resistor between data and 3V. You could use any pair of pins though > instead of Pin0, Pin1. > > Basically the way this code works is it toggles pin1 low, then > switches it back to input mode (high impedance). Then it reads at > 250000 bits/s on the SPI line, which means we get approximately 4-5 > bits for a '0' and 11-12 bits for a '1'. The rest of the code just > unpacks this into an array of 5 bytes that contain two bytes of > humidity data, two bytes of temperature, and one byte checksum. > > On your DHT11 it only has one byte each for the humidity and > temperature, I think the changes you'll need are: > temp = result[2] > humidity = result[0] > > I used https://github.com/adafruit/DHT-sensor-library/blob/master/DHT > .cpp > as a reference. > > Let me know if that works for you! > > Jim > > On 8 July 2017 at 21:01, Jim Mussared wrote: > > I just realized you had the sensor details in the subject line - > > DHT11. > > > > It looks a lot like a 1-wire device -- datasheet at > > https://cdn-shop.adafruit.com/datasheets/DHT11-chinese.pdf (and > > similar to https://cdn-shop.adafruit.com/datasheets/DHT22.pdf). I > > think you're going to have a hard time doing this from MicroPython > > on > > the micro:bit because you don't have microsecond-level timing. > > > > I recommend trying to find an I2C sensor instead - that'll be much > > easier to use. Or if you want to make it really easy, some sort of > > analog interface sensor (i.e. where you read a voltage from it). > > > > > > On 8 July 2017 at 17:10, Jim Mussared wrote: > > > Hi, > > > > > > The micro:bit doesn't have a humidity sensor built-in, so you'll > > > need > > > to use some sort of external device. I've seen a few I2C sensors, > > > but > > > it's also pretty common to see Dallas 1-wire used in these sorts > > > of > > > sensors. You'll find I2C a lot easier on the micro:bit. > > > > > > So if you could let us know which sensor you're using then we can > > > give > > > you some advice. > > > > > > Jim > > > > > > > > > On 8 July 2017 at 12:55, sasithaweerasekera via Microbit > > > wrote: > > > > Hi I want to measure and display the humidity by the microbit > > > > using microbit > > > > and the leds of the microbit, do you know the coding, because I > > > > can't find > > > > any except for bit banging which is a concept I am not familiar > > > > with, if > > > > there is a library it would help a lot > > > > Thanking you in advance for ur time; > > > > Sasitha > > > > > > > > > > > > > > > > Sent from my Samsung Galaxy smartphone. > > > > > > > > _______________________________________________ > > > > Microbit mailing list > > > > Microbit at python.org > > > > https://mail.python.org/mailman/listinfo/microbit > > > > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 455 bytes Desc: This is a digitally signed message part URL: From tgamble941 at dalriada.ballymoney.ni.sch.uk Thu Jul 20 19:00:43 2017 From: tgamble941 at dalriada.ballymoney.ni.sch.uk (T Gamble) Date: Thu, 20 Jul 2017 23:00:43 +0000 Subject: [Microbit-Python] Help - ultrasound hcsr04 sensor Message-ID: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> Hi, The MicroPython solution posted here on GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me to use the Mirco:Bit and Bit:Bot (seeBit:Bot) and HC-SR04 ultra sound sensor. The bit:bot provides pin15 for accessory connections, whereas the posted solution uses multiple pins. (I am restricted to pin15 on my bit:bot) I've tried this on Microsoft MakeCode (block editor) and it works ok - setting ping trig and echo both to pin 15, from sonar block package/module. I've been troubleshooting thus for hours on end & all I get on the MicroBit's LED matrix is the value ' -11 ' or 'Pairing Mode' weirdly! Please help. Thanks. Tim The opinions expressed are those of the individual and not the school. Internet communications are not secure and therefore the school does not accept legal responsibility for the content of this message. If the reader of this message is not the intended recipient, or the user responsible for delivering this communication to the intended recipient, you are hereby notified that any disclosure, distribution or copying of this communication is strictly prohibited. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ntoll at ntoll.org Thu Jul 20 23:17:45 2017 From: ntoll at ntoll.org (Nicholas H.Tollervey) Date: Fri, 21 Jul 2017 04:17:45 +0100 Subject: [Microbit-Python] Help - ultrasound hcsr04 sensor In-Reply-To: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> References: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> Message-ID: <099652fe-a00b-5b85-60f6-6684862a53d8@ntoll.org> I believe this is a known problem and will be fixed in the next release (in the not-too-distant-future). N. On 21/07/17 00:00, T Gamble wrote: > Hi, > > The MicroPython solution posted here on > GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me to > use the Mirco:Bit and Bit:Bot (seeBit:Bot > ) and HC-SR04 ultra sound sensor. The > bit:bot provides pin15 for accessory connections, whereas the posted > solution uses multiple pins. (I am restricted to pin15 on my bit:bot) > > I've tried this on Microsoft MakeCode (block editor) and it works ok - > setting ping trig and echo both to pin 15, from sonar block package/module. > > I've been troubleshooting thus for hours on end & all I get on the > MicroBit's LED matrix is the value ' -11 ' or 'Pairing Mode' weirdly! > > Please help. Thanks. > > Tim > > > The opinions expressed are those of the individual and not the school. > Internet communications are not secure and therefore the school does > not accept legal responsibility for the content of this message. If the > reader of this message is not the intended recipient, or the user > responsible for delivering this communication to the intended recipient, > you are hereby notified that any disclosure, distribution or copying of > this communication is strictly prohibited. > > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 455 bytes Desc: OpenPGP digital signature URL: From jim at groklearning.com Fri Jul 21 00:15:32 2017 From: jim at groklearning.com (Jim Mussared) Date: Fri, 21 Jul 2017 14:15:32 +1000 Subject: [Microbit-Python] Help - ultrasound hcsr04 sensor In-Reply-To: <099652fe-a00b-5b85-60f6-6684862a53d8@ntoll.org> References: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> <099652fe-a00b-5b85-60f6-6684862a53d8@ntoll.org> Message-ID: The bit:bot is totally amazing - we just got one for the office here. :D I actually got the ultrasonic sensor working earlier this week (using a similar approach to the temp/humidity sensor in the previous thread, and also similar to the code you linked to), but it required changes to the micropython firmware. I'm happy to share a hex file that works if you're happy to use uFlash (or manually patch the uflash.py in Mu). FYI, If you're using the latest firmware in Mu / uFlash, you might also notice crashes when controlling the robot and using the radio at the same time. This is actually fixed, but there hasn't been a firmware release since then. However I noticed that the latest firmware breaks support for NeoPixels -- I have a fix for this too but I don't understand why it broke. It's on my list for this weekend to investigate and raise some bugs / send some PRs to the micro:bit micropython repo. On 21 July 2017 at 13:17, Nicholas H.Tollervey wrote: > I believe this is a known problem and will be fixed in the next release > (in the not-too-distant-future). > > N. > > On 21/07/17 00:00, T Gamble wrote: >> Hi, >> >> The MicroPython solution posted here on >> GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me to >> use the Mirco:Bit and Bit:Bot (seeBit:Bot >> ) and HC-SR04 ultra sound sensor. The >> bit:bot provides pin15 for accessory connections, whereas the posted >> solution uses multiple pins. (I am restricted to pin15 on my bit:bot) >> >> I've tried this on Microsoft MakeCode (block editor) and it works ok - >> setting ping trig and echo both to pin 15, from sonar block package/module. >> >> I've been troubleshooting thus for hours on end & all I get on the >> MicroBit's LED matrix is the value ' -11 ' or 'Pairing Mode' weirdly! >> >> Please help. Thanks. >> >> Tim >> >> >> The opinions expressed are those of the individual and not the school. >> Internet communications are not secure and therefore the school does >> not accept legal responsibility for the content of this message. If the >> reader of this message is not the intended recipient, or the user >> responsible for delivering this communication to the intended recipient, >> you are hereby notified that any disclosure, distribution or copying of >> this communication is strictly prohibited. >> >> >> >> _______________________________________________ >> Microbit mailing list >> Microbit at python.org >> https://mail.python.org/mailman/listinfo/microbit >> > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > From david at thinkingbinaries.com Fri Jul 21 05:29:44 2017 From: david at thinkingbinaries.com (David Whale) Date: Fri, 21 Jul 2017 10:29:44 +0100 Subject: [Microbit-Python] Help - ultrasound hcsr04 sensor In-Reply-To: References: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> <099652fe-a00b-5b85-60f6-6684862a53d8@ntoll.org> Message-ID: There is an issue where if you turn the bitbot on or reset it while it is on a surface, both the line sensors are wired to the buttons. The workflow is that if you hold both buttons while powering up or reset, this initiates bluetooth pairing mode. 4tronix Gareth is aware of this. Best thing is hold it in the air when you power it on. ___________________________________________________________ David Whale, B.Sc (Hons), MIET *Software Engineer and IET Schools Liaison Officer, Essex* On 21 July 2017 at 05:15, Jim Mussared via Microbit wrote: > The bit:bot is totally amazing - we just got one for the office here. :D > > I actually got the ultrasonic sensor working earlier this week (using > a similar approach to the temp/humidity sensor in the previous thread, > and also similar to the code you linked to), but it required changes > to the micropython firmware. I'm happy to share a hex file that works > if you're happy to use uFlash (or manually patch the uflash.py in Mu). > > FYI, If you're using the latest firmware in Mu / uFlash, you might > also notice crashes when controlling the robot and using the radio at > the same time. This is actually fixed, but there hasn't been a > firmware release since then. However I noticed that the latest > firmware breaks support for NeoPixels -- I have a fix for this too but > I don't understand why it broke. It's on my list for this weekend to > investigate and raise some bugs / send some PRs to the micro:bit > micropython repo. > > On 21 July 2017 at 13:17, Nicholas H.Tollervey wrote: > > I believe this is a known problem and will be fixed in the next release > > (in the not-too-distant-future). > > > > N. > > > > On 21/07/17 00:00, T Gamble wrote: > >> Hi, > >> > >> The MicroPython solution posted here on > >> GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me > to > >> use the Mirco:Bit and Bit:Bot (seeBit:Bot > >> ) and HC-SR04 ultra sound sensor. > The > >> bit:bot provides pin15 for accessory connections, whereas the posted > >> solution uses multiple pins. (I am restricted to pin15 on my bit:bot) > >> > >> I've tried this on Microsoft MakeCode (block editor) and it works ok - > >> setting ping trig and echo both to pin 15, from sonar block > package/module. > >> > >> I've been troubleshooting thus for hours on end & all I get on the > >> MicroBit's LED matrix is the value ' -11 ' or 'Pairing Mode' weirdly! > >> > >> Please help. Thanks. > >> > >> Tim > >> > >> > >> The opinions expressed are those of the individual and not the school. > >> Internet communications are not secure and therefore the school does > >> not accept legal responsibility for the content of this message. If the > >> reader of this message is not the intended recipient, or the user > >> responsible for delivering this communication to the intended recipient, > >> you are hereby notified that any disclosure, distribution or copying of > >> this communication is strictly prohibited. > >> > >> > >> > >> _______________________________________________ > >> Microbit mailing list > >> Microbit at python.org > >> https://mail.python.org/mailman/listinfo/microbit > >> > > > > > > _______________________________________________ > > Microbit mailing list > > Microbit at python.org > > https://mail.python.org/mailman/listinfo/microbit > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dvhill at gmail.com Fri Jul 21 11:47:29 2017 From: dvhill at gmail.com (Daniel Hill) Date: Fri, 21 Jul 2017 15:47:29 +0000 Subject: [Microbit-Python] micro:badge for hacker conferences Message-ID: I cooked up a pager network for DEFCON 25 next week using MicroPython and the micro:bit. It's very basic, but i wanted to share. https://github.com/RangerDan/dc25-micro-badge This platform is perfect for tinkering, and I'm hoping to see how many features we can get jammed into the tiny package. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ntoll at ntoll.org Fri Jul 21 13:31:41 2017 From: ntoll at ntoll.org (Nicholas H.Tollervey) Date: Fri, 21 Jul 2017 18:31:41 +0100 Subject: [Microbit-Python] micro:badge for hacker conferences In-Reply-To: References: Message-ID: Great stuff! :-) Love the use of the skull animation. N. On 21/07/17 16:47, Daniel Hill wrote: > I cooked up a pager network for DEFCON 25 next week using MicroPython > and the micro:bit. It's very basic, but i wanted to share. > > https://github.com/RangerDan/dc25-micro-badge > > This platform is perfect for tinkering, and I'm hoping to see how many > features we can get jammed into the tiny package. > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 455 bytes Desc: OpenPGP digital signature URL: From mal at egenix.com Fri Jul 21 17:15:04 2017 From: mal at egenix.com (M.-A. Lemburg) Date: Fri, 21 Jul 2017 23:15:04 +0200 Subject: [Microbit-Python] micro:badge for hacker conferences In-Reply-To: References: Message-ID: <92c4dc0b-a60a-8eba-a852-5157a961b70c@egenix.com> On 21.07.2017 19:31, Nicholas H.Tollervey wrote: > Great stuff! :-) > > Love the use of the skull animation. The description of the badge code mentions BTLE - does MicroPython now support BTLE on the MicroBit ? At a sprint a year ago we created a mesh network of MBs using the radio. This worked reasonably well. > N. > > On 21/07/17 16:47, Daniel Hill wrote: >> I cooked up a pager network for DEFCON 25 next week using MicroPython >> and the micro:bit. It's very basic, but i wanted to share. >> >> https://github.com/RangerDan/dc25-micro-badge >> >> This platform is perfect for tinkering, and I'm hoping to see how many >> features we can get jammed into the tiny package. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Jul 21 2017) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From jim at groklearning.com Sat Jul 22 09:20:23 2017 From: jim at groklearning.com (Jim Mussared) Date: Sat, 22 Jul 2017 23:20:23 +1000 Subject: [Microbit-Python] Help - ultrasound hcsr04 sensor In-Reply-To: <9EA1B24479BB314F9AAC8E2F0CBCA257407D7C47@PDC-EXC-MB02.c2ken.net> References: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> <099652fe-a00b-5b85-60f6-6684862a53d8@ntoll.org> <9EA1B24479BB314F9AAC8E2F0CBCA257407D7C47@PDC-EXC-MB02.c2ken.net> Message-ID: This is the rough code - it won't work on current firmware which doesn't have spi.deinit() or the ability to use pin15 for digital or switch between SPI and digital. The actual plan is to add support for a way to count the length of a pulse akin to regular MicroPython's machine.time_pulse_us function rather than the horrible SPI hack. The bitbot has pin 15 connected to both Trig and Echo which is why this doesn't work easily. However, if you were using a HCSR04 sensor connected to other pins, and used different pins for trig and echo, you could make the below code work on current firmware. See the second code snippet (untested, sorry). --- First snippet (shared trig/echo pin, doesn't work on current firmware) --- from microbit import * import gc DISTANCE_BITS_PER_CM = 10 # these are just guesses, need to be calibrated DISTANCE_OFFSET = 3 def distance(): gc.disable() pin15.read_digital() pin15.write_digital(True) spi.init(baudrate=50000,bits=8,mode=0,sclk=pin20,mosi=pin14,miso=pin15) x = spi.read(100) high_bytes = x.count(b'\xff') high_bits = high_bytes*8 + bin(x[high_bytes]).count(1) x = None spi.deinit() gc.enable() gc.collect() print(high_bits * DISTANCE_BITS_PER_CM + DISTANCE_OFFSET) while True: print(distance()) sleep(200) --- Second snippet (should work with separate trig/echo pins) -- from microbit import * import gc DISTANCE_BITS_PER_CM = 10 # these are just guesses, need to be calibrated DISTANCE_OFFSET = 3 TRIG_PIN = pin0 ECHO_PIN = pin1 spi.init(baudrate=50000,bits=8,mode=0,miso=ECHO_PIN) def distance(): gc.disable() TRIG_PIN.write_digital(False) TRIG_PIN.write_digital(True) x = spi.read(100) high_bytes = x.count(b'\xff') high_bits = high_bytes*8 + bin(x[high_bytes]).count(1) x = None gc.enable() gc.collect() print(high_bits * DISTANCE_BITS_PER_CM + DISTANCE_OFFSET) while True: print(distance()) sleep(200) On 22 July 2017 at 22:44, T Gamble wrote: > Hi Jim, > > Could you share the Python code you used to get the Bit:Bot's HCSR04 sensor working? I assume you've managed to use Pin15 for both Trig and Echo. (Which pin did you use for SPI?) > > thanks for the hope! > > tim > > ________________________________________ > From: Microbit [microbit-bounces+tgamble941=c2kni.net at python.org] on behalf of Jim Mussared via Microbit [microbit at python.org] > Sent: 21 July 2017 05:15 > To: For Pythonic MicroBit related discussions > Cc: Jim Mussared > Subject: Re: [Microbit-Python] Help - ultrasound hcsr04 sensor > > The bit:bot is totally amazing - we just got one for the office here. :D > > I actually got the ultrasonic sensor working earlier this week (using > a similar approach to the temp/humidity sensor in the previous thread, > and also similar to the code you linked to), but it required changes > to the micropython firmware. I'm happy to share a hex file that works > if you're happy to use uFlash (or manually patch the uflash.py in Mu). > > FYI, If you're using the latest firmware in Mu / uFlash, you might > also notice crashes when controlling the robot and using the radio at > the same time. This is actually fixed, but there hasn't been a > firmware release since then. However I noticed that the latest > firmware breaks support for NeoPixels -- I have a fix for this too but > I don't understand why it broke. It's on my list for this weekend to > investigate and raise some bugs / send some PRs to the micro:bit > micropython repo. > > On 21 July 2017 at 13:17, Nicholas H.Tollervey wrote: >> I believe this is a known problem and will be fixed in the next release >> (in the not-too-distant-future). >> >> N. >> >> On 21/07/17 00:00, T Gamble wrote: >>> Hi, >>> >>> The MicroPython solution posted here on >>> GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me to >>> use the Mirco:Bit and Bit:Bot (seeBit:Bot >>> ) and HC-SR04 ultra sound sensor. The >>> bit:bot provides pin15 for accessory connections, whereas the posted >>> solution uses multiple pins. (I am restricted to pin15 on my bit:bot) >>> >>> I've tried this on Microsoft MakeCode (block editor) and it works ok - >>> setting ping trig and echo both to pin 15, from sonar block package/module. >>> >>> I've been troubleshooting thus for hours on end & all I get on the >>> MicroBit's LED matrix is the value ' -11 ' or 'Pairing Mode' weirdly! >>> >>> Please help. Thanks. >>> >>> Tim >>> >>> >>> The opinions expressed are those of the individual and not the school. >>> Internet communications are not secure and therefore the school does >>> not accept legal responsibility for the content of this message. If the >>> reader of this message is not the intended recipient, or the user >>> responsible for delivering this communication to the intended recipient, >>> you are hereby notified that any disclosure, distribution or copying of >>> this communication is strictly prohibited. >>> >>> >>> >>> _______________________________________________ >>> Microbit mailing list >>> Microbit at python.org >>> https://mail.python.org/mailman/listinfo/microbit >>> >> >> >> _______________________________________________ >> Microbit mailing list >> Microbit at python.org >> https://mail.python.org/mailman/listinfo/microbit >> > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit From tgamble941 at dalriada.ballymoney.ni.sch.uk Sat Jul 22 08:34:22 2017 From: tgamble941 at dalriada.ballymoney.ni.sch.uk (T Gamble) Date: Sat, 22 Jul 2017 12:34:22 +0000 Subject: [Microbit-Python] Help - ultrasound hcsr04 sensor In-Reply-To: References: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> <099652fe-a00b-5b85-60f6-6684862a53d8@ntoll.org> , Message-ID: <9EA1B24479BB314F9AAC8E2F0CBCA257407D7C2D@PDC-EXC-MB02.c2ken.net> @Jim Mussared Yes Jim, I'm happy to use whatever means to get the HCSR04 sensor working. I will download uFlash now and see if that makes any difference. In the code I submitted, what edits do I need to make? thanks tim ________________________________ From: Microbit [microbit-bounces+tgamble941=c2kni.net at python.org] on behalf of David Whale [david at thinkingbinaries.com] Sent: 21 July 2017 10:29 To: For Pythonic MicroBit related discussions Subject: Re: [Microbit-Python] Help - ultrasound hcsr04 sensor There is an issue where if you turn the bitbot on or reset it while it is on a surface, both the line sensors are wired to the buttons. The workflow is that if you hold both buttons while powering up or reset, this initiates bluetooth pairing mode. 4tronix Gareth is aware of this. Best thing is hold it in the air when you power it on. ___________________________________________________________ David Whale, B.Sc (Hons), MIET Software Engineer and IET Schools Liaison Officer, Essex On 21 July 2017 at 05:15, Jim Mussared via Microbit > wrote: The bit:bot is totally amazing - we just got one for the office here. :D I actually got the ultrasonic sensor working earlier this week (using a similar approach to the temp/humidity sensor in the previous thread, and also similar to the code you linked to), but it required changes to the micropython firmware. I'm happy to share a hex file that works if you're happy to use uFlash (or manually patch the uflash.py in Mu). FYI, If you're using the latest firmware in Mu / uFlash, you might also notice crashes when controlling the robot and using the radio at the same time. This is actually fixed, but there hasn't been a firmware release since then. However I noticed that the latest firmware breaks support for NeoPixels -- I have a fix for this too but I don't understand why it broke. It's on my list for this weekend to investigate and raise some bugs / send some PRs to the micro:bit micropython repo. On 21 July 2017 at 13:17, Nicholas H.Tollervey > wrote: > I believe this is a known problem and will be fixed in the next release > (in the not-too-distant-future). > > N. > > On 21/07/17 00:00, T Gamble wrote: >> Hi, >> >> The MicroPython solution posted here on >> GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me to >> use the Mirco:Bit and Bit:Bot (seeBit:Bot >> ) and HC-SR04 ultra sound sensor. The >> bit:bot provides pin15 for accessory connections, whereas the posted >> solution uses multiple pins. (I am restricted to pin15 on my bit:bot) >> >> I've tried this on Microsoft MakeCode (block editor) and it works ok - >> setting ping trig and echo both to pin 15, from sonar block package/module. >> >> I've been troubleshooting thus for hours on end & all I get on the >> MicroBit's LED matrix is the value ' -11 ' or 'Pairing Mode' weirdly! >> >> Please help. Thanks. >> >> Tim >> >> >> The opinions expressed are those of the individual and not the school. >> Internet communications are not secure and therefore the school does >> not accept legal responsibility for the content of this message. If the >> reader of this message is not the intended recipient, or the user >> responsible for delivering this communication to the intended recipient, >> you are hereby notified that any disclosure, distribution or copying of >> this communication is strictly prohibited. >> >> >> >> _______________________________________________ >> Microbit mailing list >> Microbit at python.org >> https://mail.python.org/mailman/listinfo/microbit >> > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > _______________________________________________ Microbit mailing list Microbit at python.org https://mail.python.org/mailman/listinfo/microbit -------------- next part -------------- An HTML attachment was scrubbed... URL: From jim at groklearning.com Sat Jul 22 11:00:41 2017 From: jim at groklearning.com (Jim Mussared) Date: Sun, 23 Jul 2017 01:00:41 +1000 Subject: [Microbit-Python] Help - ultrasound hcsr04 sensor In-Reply-To: <9EA1B24479BB314F9AAC8E2F0CBCA257407D7C2D@PDC-EXC-MB02.c2ken.net> References: <5921DBB4-78F4-4777-9D43-F8AC5D815BC8@dalriada.ballymoney.ni.sch.uk> <099652fe-a00b-5b85-60f6-6684862a53d8@ntoll.org> <9EA1B24479BB314F9AAC8E2F0CBCA257407D7C2D@PDC-EXC-MB02.c2ken.net> Message-ID: Hi Tim, Here's a tested and somewhat calibrated code sample that works with the current Mu / uFlash firmware. https://gist.github.com/jimmo/14c6194578f721477c5c88e5dbbcfcef Some things to be aware of: - This won't work on a bit:bot (can't use pin15) - This requires that ECHO and TRIG are separate pins. - You need to supply the HC-SR04 with 5V Vcc -- you can't power it from the micro:bit. - To make the echo output 3.3V safe to connect to the micro:bit, you need to use a level shifter (or a simple voltage divider, e.g. 18k/10kOhm -- "ECHO ---10k--- pin1 ---18k--- GND") The bit:bot does those last two things for you of course. Jim On 22 July 2017 at 22:34, T Gamble wrote: > @Jim Mussared > > > > Yes Jim, I'm happy to use whatever means to get the HCSR04 sensor working. I > will download uFlash now and see if that makes any difference. > > > > In the code I submitted, what edits do I need to make? > > > > thanks > > > > tim > > ________________________________ > > From: Microbit [microbit-bounces+tgamble941=c2kni.net at python.org] on behalf > of David Whale [david at thinkingbinaries.com] > Sent: 21 July 2017 10:29 > To: For Pythonic MicroBit related discussions > Subject: Re: [Microbit-Python] Help - ultrasound hcsr04 sensor > > There is an issue where if you turn the bitbot on or reset it while it is on > a surface, both the line sensors are wired to the buttons. > > The workflow is that if you hold both buttons while powering up or reset, > this initiates bluetooth pairing mode. > > 4tronix Gareth is aware of this. > > Best thing is hold it in the air when you power it on. > > > ___________________________________________________________ > David Whale, B.Sc (Hons), MIET > Software Engineer and IET Schools Liaison Officer, Essex > > > On 21 July 2017 at 05:15, Jim Mussared via Microbit > wrote: >> >> The bit:bot is totally amazing - we just got one for the office here. :D >> >> I actually got the ultrasonic sensor working earlier this week (using >> a similar approach to the temp/humidity sensor in the previous thread, >> and also similar to the code you linked to), but it required changes >> to the micropython firmware. I'm happy to share a hex file that works >> if you're happy to use uFlash (or manually patch the uflash.py in Mu). >> >> FYI, If you're using the latest firmware in Mu / uFlash, you might >> also notice crashes when controlling the robot and using the radio at >> the same time. This is actually fixed, but there hasn't been a >> firmware release since then. However I noticed that the latest >> firmware breaks support for NeoPixels -- I have a fix for this too but >> I don't understand why it broke. It's on my list for this weekend to >> investigate and raise some bugs / send some PRs to the micro:bit >> micropython repo. >> >> On 21 July 2017 at 13:17, Nicholas H.Tollervey wrote: >> > I believe this is a known problem and will be fixed in the next release >> > (in the not-too-distant-future). >> > >> > N. >> > >> > On 21/07/17 00:00, T Gamble wrote: >> >> Hi, >> >> >> >> The MicroPython solution posted here on >> >> GitHub https://github.com/fizban99/microbit_hcsr04 will not enable me >> >> to >> >> use the Mirco:Bit and Bit:Bot (seeBit:Bot >> >> ) and HC-SR04 ultra sound sensor. >> >> The >> >> bit:bot provides pin15 for accessory connections, whereas the posted >> >> solution uses multiple pins. (I am restricted to pin15 on my bit:bot) >> >> >> >> I've tried this on Microsoft MakeCode (block editor) and it works ok - >> >> setting ping trig and echo both to pin 15, from sonar block >> >> package/module. >> >> >> >> I've been troubleshooting thus for hours on end & all I get on the >> >> MicroBit's LED matrix is the value ' -11 ' or 'Pairing Mode' weirdly! >> >> >> >> Please help. Thanks. >> >> >> >> Tim >> >> >> >> >> >> The opinions expressed are those of the individual and not the school. >> >> Internet communications are not secure and therefore the school does >> >> not accept legal responsibility for the content of this message. If the >> >> reader of this message is not the intended recipient, or the user >> >> responsible for delivering this communication to the intended >> >> recipient, >> >> you are hereby notified that any disclosure, distribution or copying of >> >> this communication is strictly prohibited. >> >> >> >> >> >> >> >> _______________________________________________ >> >> Microbit mailing list >> >> Microbit at python.org >> >> https://mail.python.org/mailman/listinfo/microbit >> >> >> > >> > >> > _______________________________________________ >> > Microbit mailing list >> > Microbit at python.org >> > https://mail.python.org/mailman/listinfo/microbit >> > >> _______________________________________________ >> Microbit mailing list >> Microbit at python.org >> https://mail.python.org/mailman/listinfo/microbit > > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > From dvhill at gmail.com Sat Jul 22 11:34:09 2017 From: dvhill at gmail.com (Daniel Hill) Date: Sat, 22 Jul 2017 15:34:09 +0000 Subject: [Microbit-Python] micro:badge Message-ID: Oops! Back before we were using pxt I thought i was able to try it. It uses just the radio now. The first thing I'm discussing with badge holders is a mesh network protocol. As this is for DEFCON, the security challenges here are at the forefront. Can we avoid replay attacks? Add privacy? How about authentication? All in the tight little microcontroller memory size. I think I'll stick with adding mundane stuff until the con. Was thinking of a new feature where you would hold it face down in the air and it would tell you how many pairings are in range with a ping-like challenge/response. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ntoll at ntoll.org Sat Jul 22 11:58:36 2017 From: ntoll at ntoll.org (Nicholas H.Tollervey) Date: Sat, 22 Jul 2017 16:58:36 +0100 Subject: [Microbit-Python] micro:badge In-Reply-To: References: Message-ID: <9426d908-3747-eacf-296c-49def7812d2e@ntoll.org> Daniel, This sounds great! Please do keep asking questions, when I was writing the (upcoming) MicroPython book, one of the examples I used is a very simple mesh network for inter-device communication. It's a fun problem, but I left it as an exercise for the reader to add security related challenges (although I have some thoughts about the things you mention). Best of luck, N. On 22/07/17 16:34, Daniel Hill wrote: > Oops! Back before we were using pxt I thought i was able to try it. It > uses just the radio now. > > The first thing I'm discussing with badge holders is a mesh network > protocol. As this is for DEFCON, the security challenges here are at the > forefront. Can we avoid replay attacks? Add privacy? How about > authentication? All in the tight little microcontroller memory size. > > I think I'll stick with adding mundane stuff until the con. Was thinking > of a new feature where you would hold it face down in the air and it > would tell you how many pairings are in range with a ping-like > challenge/response. > > > _______________________________________________ > Microbit mailing list > Microbit at python.org > https://mail.python.org/mailman/listinfo/microbit > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 455 bytes Desc: OpenPGP digital signature URL: