Last night, I thought about the fact that the new display module I have been sent, with its driver circuitry, only uses 4 pins rather than the 12 I was expecting on the naked 4 digit LED. That means that I can connect the display module, the HC-SR04 ultrasonic sensor, AND the DS3231 RTC to the Uno all at the same time (and still have pins to spare). By shuffling things up a bit on my breadboard, I could fit the RTC module alongside the ultrasonic module, so that a) it has a semi-permanent home and I don't have to worry about it getting shorted out any more, and b) I can use the display for either the clock or the rainwater tank gauge just by reloading the required sketch. So I set to, and did just that.
Unfortunately, the combination of my poor eyesight, low light in the evening, and trying to line up small cables with small holes means - inevitably - I did something wrong - with style and panache! Actually, it turns out I did a couple of somethings wrong, but please, read on...
Eager to see if the RTC was still keeping time after a week in its little bag, I plugged it all in and reloaded my little clock sketch. Nothing... Zip... Nada! Well - what a let down. So, hoping I had simply dislodged a wire to the display, I reloaded the tank gauge sketch as a test, but that worked OK. I tried the clock again, but still nothing. So it must be the RTC wiring or the RTC itself
I decided to pull out the RTC and the DuPont cables to it and start again. I grabbed the RTC and burned my thumb on the battery - it was very hot! I figured this meant I had a power problem and quickly found that I had reversed the Vcc and GND connections to the RTC board... I'm really surprised I hadn't buggered up everything else on the breadboard - my Uno included!
Anyway - I removed the battery and let everything cool down and swapped the connections back the way they should be, then tried again. This time, the display came back to life (whoopee!), but I was a little disappointed and somewhat surprised to see the time was 13:65!
I guess that just maybe, reversing the polarity and almost setting fire to the module may have had a slightly adverse affect on the data - possibly - so I reloaded the set time sketch, reset the time and tried again. It was still showing 13:65 - weird... Uh oh - I started to get that feeling of dread again - you know, the one I got just seconds after hitting the button to buy a Pro Mini that I realised I knew nothing about..? After the first RTC I bought being DOA, perhaps I've now killed this RTC as well.
I reloaded the tank gauge sketch, just to make sure I hadn't fried the Uno as well, but that seemed to be working OK. I tried the clock once more - and the time was still 13:65 - DAMMIT! What was worse, was that the time display seemed static - even after 5 minutes (carefully keeping an eye on the temperature of the battery), it was still apparently 13:65 - I kind of hoped it might tick over each minute and show 13:70.
Well - I had removed and reseated the RTC module, and the Vcc/GND wires had been swapped, but I hadn't touched the SDA and SCL cables yet... Yes, you've guessed it - I had them round the wrong way too! Good grief, just how much wronger (yes - its a word) could I possibly have got this? After swapping those two around, and running the set sketch again, the display finally shows the correct time. Just to make sure, I pulled the rest of the clock data (YYMMDD, DoW, and hhmmss) and displayed them on the Serial console - phew - all seems ok. I haven't destroyed the chip after all, despite my best efforts. Mind you, having abused the battery like that, I'm not sure how long that is going to last now. It has kept the RTC going for around 24 hrs at the time of writing this, and the time is still correct to within about a second. I'm just counting my blessings, and vow that I am not going to touch that module again until it goes into its permanent home on my portable workbench.
Lesson learned? Accept that I'm getting older and my eyesight ain't what it used to be. Don't struggle in dim light where you can't see the difference between a grey and lilac cable, or manage to line up the red and black cables with the appropriate pins on the Uno... TURN SOME LIGHTS ON!
An introduction to basic elctronics, and designing circuits and programs to be used with an Arduino microcontroller board such as the Arduino Uno. Learn with me as I take things apart, investigate, research, and gradually build my own knowledge.
Thursday, 9 November 2017
Thursday, 2 November 2017
Water Tank Depth Gauge - 3 (The Prototype)
Last night, I dismantled my clock (carefully placing the DS3231 RTC in a bag to prevent any accidental short-circuiting), and cobbled together the Uno, HC-SR04 ultrasonic sensor, and my (clock oriented) 4 digit LED, to make a very nerdy looking ultrasonic tape measure (Dr Who - eat your heart out - sonic screwdriver, pah!).
I kept the code very basic (in fact, it is less than 50 lines of code including comments and spacing), and this quick and dirty version just shows the distance measured in cms on the display.
I did a few random measuring experiments, and was quite impressed with the apparent accuracy! I haven't yet set up a test rig to check measurements across the entire range, but I did a few spot checks and found it to be within 1-2 cms at distances up to a couple of metres, though I have noticed occasional sporadic and momentary wild readings. For example, while writing this, the sofa across the other side of the room is apparently 3.44 metres away - most of the time, but once in a while, just for a split second, it leaps forwards to 3.01 or even 2.88 metres, and immediately jumps back again! Perhaps I shouldn't have made that comment about Dr Who... I think he is getting his own back, by playing around with my interspatial dimensionality continuum :-/ Or maybe it is just soft furnishings don't give a solid enough echo...
The ebay seller has agreed to send me a new display unit (he thinks his 'worker' has made a mistake), and says he will find a way to get the replacement to me quickly so I don't have to wait another 3-4 weeks. Now I just hope that his 'worker' has actually understood the mistake, and doesn't just send the same thing again. Oh well, if he does, then I'll just use it to display the 3 digit number and have a spare clock display I can mount onto my portable workbench.
I kept the code very basic (in fact, it is less than 50 lines of code including comments and spacing), and this quick and dirty version just shows the distance measured in cms on the display.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <TM1637Display.h> #include <NewPing.h> // LED Module connection pins (Digital Pins) #define CLK 9 #define DIO 8 // pins for HC-SR04 #define pinTrig 6 #define pinEcho 7 NewPing sonar(pinTrig, pinEcho, 400); // 400 is max claimed ability, though it actually keeps going till around 450 // Initialise LED TM1637Display display(CLK, DIO); void setup() { // setup the sonar pins pinMode(pinTrig, OUTPUT); pinMode(pinEcho, INPUT); // turn off annoying LED on 13 pinMode(13, OUTPUT); digitalWrite(13,LOW); // set brightness of LED // (0-7,true/false) where 0=min 7=max (0-3 have greatest impact), true=on and false=off display.setBrightness(1,true); // set all segments off for all digits uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 }; display.setSegments(data); } void loop() { // Take 10 readings, and use median duration. int duration = sonar.ping_median(10); // duration is in microseconds // Convert the averaged delay time to distance (water surface to sensor). int cms = duration / 29 / 2; // speed of sound is 29 microsecs per cm (x2 for round trip) // display distance on LED display.showNumberDec(cms,false,4,4); } |
I did a few random measuring experiments, and was quite impressed with the apparent accuracy! I haven't yet set up a test rig to check measurements across the entire range, but I did a few spot checks and found it to be within 1-2 cms at distances up to a couple of metres, though I have noticed occasional sporadic and momentary wild readings. For example, while writing this, the sofa across the other side of the room is apparently 3.44 metres away - most of the time, but once in a while, just for a split second, it leaps forwards to 3.01 or even 2.88 metres, and immediately jumps back again! Perhaps I shouldn't have made that comment about Dr Who... I think he is getting his own back, by playing around with my interspatial dimensionality continuum :-/ Or maybe it is just soft furnishings don't give a solid enough echo...
The ebay seller has agreed to send me a new display unit (he thinks his 'worker' has made a mistake), and says he will find a way to get the replacement to me quickly so I don't have to wait another 3-4 weeks. Now I just hope that his 'worker' has actually understood the mistake, and doesn't just send the same thing again. Oh well, if he does, then I'll just use it to display the 3 digit number and have a spare clock display I can mount onto my portable workbench.
Subscribe to:
Comments (Atom)
