jguille2 / SA5

Scratch/Snap and Arduino Synchronized
GNU General Public License v3.0
10 stars 3 forks source link

measure the dark time of a forked light barrier #4

Closed seteahconnoc closed 7 years ago

seteahconnoc commented 7 years ago

Perhaps, anyone could help me with my Snap4Arduino problem: https://github.com/bromagosa/Snap4Arduino/issues/204

I was not quite sure, where to post the issue. So, please excuse this link.

seteahconnoc commented 7 years ago

I guess, I need a little support on "pulseIn". bildschirmfoto von 2017-11-02 18-26-11 For testing purposes, I aim to connect two pins. One pin should be blinking, the other one should read the duration via "pulseIn". In this example, I used the PWM pins 13 and 7. The led indicator on pin 13 was blinking, but "pulseIn" just says "0". Am I using the appropriate pins on my Mega 2560? What could be wrong? In slightly other test runs, I got irreproducable numbers by using the "pulseIn" block. Any help on my newbie question would be welcome.

jguille2 commented 7 years ago

Hi @seteahconnoc ,

Continue...

Joan

seteahconnoc commented 7 years ago

I appreciate your patience. Sadly, I 'm just not successful by now. bildschirmfoto von 2017-11-03 11-01-35 I connected pin 13 and pin 7. By activating the blocks on the left, pin 13 is blinking - as indicated by the led. At first, I used "digital reading" (part A), which worked just fine. Then, I used "pulseIn" (part B) with a 0.5 s timeout. The effect was a flickering indicator led on pin 13 and a speech bubble with an "0". I guess, there 's something, that I just don 't understand by now.

jguille2 commented 7 years ago

Hi, I'm not sure if this is the problem... but can you test the second (B) forever loop adding a little delay (for example a wait 1 secs)?

I think the forever loop restarts without time to get the measure.

In fact, you can test it without this loop... Run the forever blink and try pulseIn block manually (clicking it) and try to adjust timeout value. After this... if you want to read pulseIn into a loop, add the delay to allow time for the measurements.

seteahconnoc commented 7 years ago

I tried, what you said, yet still there 's no success. Isn 't it strange, that the indicator led on pin 13 stops blinking while I activate the "pulseIn" block?

seteahconnoc commented 7 years ago

Meanwhile, I tried different things - sadly, still without success.

(1) I 've clicked "pulseIn (µs) pin '13' HIGH timeout: '1000000'". During the next second, I connected very shortly pin 13 and the 5V pin of the same arduino.

(2) I 've clicked "pulseIn (µs) pin '13' HIGH timeout: '1000000'". During the next second, I 've clicked "pulseOut pin '13' HIGH '100000' '100000' '100000'".

(3) I 've clicked "pulseIn (µs) pin '13' HIGH timeout: '1000000'". During the next second, I 've clicked "pulseOut pin '7' HIGH '100000' '100000' '100000'".

Effectively, all I got was a speech bubble, saying "0". How do I get "pulseIn" to say anything different than that?


I like using "Snap!", Snap4Arduino and SA5. Thank you for your work. But right now, I am just curious to find my (silly) mistake.

jguille2 commented 7 years ago

Hi @seteahconnoc , Not a silly mistake... and with your last description, I see where is the problem (sorry for haven't seen it before :( )

I'll take a look to this problem and try to improve this behavior... but I'm not sure I can get it (I don't want to make big changes into Firmata... I only wanted to add some needed features). But, knowing this, you can go on...

I hope we have found the problem in this blocking behavior of the firmata pulseIn.

Let's continue...

seteahconnoc commented 7 years ago

Thanks, that sounds promising. Right now, I neither can get a grip on a second Arduino board nor on a light barrier. I guessed, this would do the thing:

"I 've clicked "pulseIn (µs) pin '13' HIGH timeout: '1000000'". During the next second, I connected very shortly pin 13 and the 5V pin of the same Arduino board."

But - as said - this won 't work.

I know, that plugging in something on pin 13 doesn 't give a square signal. There has to be some kind of latence and contact bounce. But I thought, that I would receive at least something different from just a zero.

jguille2 commented 7 years ago

Yes,

But you can test it with a longer timeout (not very long... that it causes a board desconnection... but test with 3 o 4 seconds).

And important! To make the pulse you must do GROUND-5V-GROUND. If you only connect 5V and disconnect, the pin state is not going to 0 automatically. Then connect ground before you click pulseIn and after this, connect to 5V and return to ground. Of course you can build a switch to do it easier.

After this test... I thought you could test with the barrier idea. I guess you have a light detector (the one you connected to 7)... and then, you don't need a real barrier... you only have to cover and uncover the detector (or the light emitter) and that is all.

Tell me your results...

seteahconnoc commented 7 years ago

:) It 's working finally. Thank you very much for the instructions. It 's only a little side project, but I have to say, that it makes me quite happy. Perhaps, our github conversation can help someone else, too.


A few words on my further proceedings: I am planning to use this forked light barrier:

http://www.uranmaschine.de/55510.Phywe-Lichtschranke_Invertierer/index.php

It 's an old device from a school's collection for physics classes. Originally, it comes with an old electronic counter like this:

http://www.uranmaschine.de/87203.Neva_7203_Elektronischer_Zaehler/

Nowadays, you can use different proprietary software/hardware combinations to measure the dark time. I hope, that the usage of the old light barrier with "Snap!" shows some creative potential. We will see.

Best wishes to Catalonia in these turbulent times.