Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Make it Pulse in MakeCode
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Make it Pulse in MakeCode

by V2man on Sun Nov 10, 2019 12:52 pm

@ adafruit2
The plotting vertical axis numbers in Makecode match the data point values!
The values of the data points of samples(i) - mean are couple of orders of magnitude smaller in Makecode than in MU.
In the original CircuitPython code there were a few statements converting integers to floating point.
I am refering to oversample += float(light.value) and mean = sum(samples) / float(len(samples))
In Makecode there are integer divide and multiply blocks under math --> square root but no float.
How do I convert an integer to floating point in Makecode?

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by V2man on Sun Nov 10, 2019 1:55 pm

If I remove float to define oversample += light.value and mean = sum(samples) / len(samples) in CircuitPython version there is no noticeable difference in the output.
@ adafruit2 There is a discrepancy between the values outputted by Makecode vs MU or I missed something in the translation that I am not seeing.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by V2man on Tue Nov 12, 2019 7:02 pm

After checking with console statements in Makecode the sum variable calculated in a for loop using the function SUM is always zero.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by V2man on Wed Nov 13, 2019 1:43 pm

Today I am getting an output on sum. Weird! I don't know if Makecode version just changed or because I updated to CircuitPython 5.0.0-alpha.5 and libraries on the CircuitPython side.
Just adding the console log sum effects the final result!
When I switch back to Makecode from CircuitPython I get a message from Makecode that it could not complete the download even though I started in Bootloader mode.
In Makecode once you have downloaded once you do not have to put the board in Bootloader mode by pressing the reset once to make a change. This works most of the time but once in awhile I get the message that it could not complete my download. So I press the reset once and try again. A similar event happens when I go from Makecode to CircuitPython. I have to do it again.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by V2man on Wed Nov 13, 2019 9:11 pm

Today I got this in Makecode after two days of not being able to repeat results. This is with NUM_OVERSAMPLE = 10, NUM_SAMPLES = 20, pause 100 ms.

PulseMUplot1113.png
PulseMUplot1113.png (15.71 KiB) Viewed 223 times


And after 10 measurements during which I jumped back and forth between doing a console plot of sum and removing monitoring of sum I could not repeat the results shown in the attachment. At least the sum variable is not zero. I still cannot reconcile the values of sample(i) - mean on Makecode vs CircuitPython.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by V2man on Thu Nov 14, 2019 2:51 am

Replaced Console log with DataLogger
Here's the result of using DataLogger in Makecode. Sampling interval of DataLogger set to 10 ms and pause set to 25 ms. The best way to hold your finger is at a -45 degree angle from the USB connector and placed on SCL/A4 and SDA/A5. The tip of the finger even and covering the the light sensor but not actually touching the sensor.

HB-Nov-DataLog.png
HB-Nov-DataLog.png (94.53 KiB) Viewed 210 times


HB-Nov-DataLogger.PNG
HB-Nov-DataLogger.PNG (163.33 KiB) Viewed 210 times
Attachments
circuitplayground-HB-Nov-DataLogger.uf2
(322.5 KiB) Downloaded 9 times

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by V2man on Thu Nov 14, 2019 1:45 pm

WARNING NEED TO INSTALL A TIMER TO STOP LOGGING!
Don't use the last uf2!
There is a problem with datalogger. If you keep logging the csv file under MAKECODE/SPIFLASH gets large enough to exceed the storage capacity of MAKECODE drive. Then you get error 11 1011 0110 = 0x3C6

I tried deleting SPIFLASH dir and downloading an empty Makecode uf2 without success.
I copied CircuitPython uf2 then back to Makecode uf2.
Recovered.
Can't use this file until I learn about timers and clearing the contents of log.csv so its size remains small.
I currently added On button A to turn data logger on and On button B to turn data logger off. But this needs to be automated.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by V2man on Fri Nov 15, 2019 2:04 pm

I could not find a way to fool Makecode by inserting a Data Logger from data logger extension but only using it to set set data logger sampling interval. Remove log.csv from the Storage extension does not really erase the file. Only way is to go to CIRCUITPY and back to Makecode. The log.csv just keeps getting bigger and bigger. Some control on writing to log.csv can be controlled by using set data logger on/off. Using a conditional statement with size of file and overwrite file with " " from Storage extension to restrict log.csv from growing did not work.

So right now with NUM_OVERSAMPLE = 16, NUM_SAMPLES = 64 and pause = 1 ms with circuitplayground-Heartbeat-Nov.uf2 I am getting this:

HB-Nov-ConsoleLog16641.PNG
HB-Nov-ConsoleLog16641.PNG (39.8 KiB) Viewed 173 times

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: Make it Pulse in MakeCode

by adafruit2 on Sun Nov 24, 2019 1:27 pm

that looks pretty good - yah logging waveforms will fill up the disk fast. did your makecode example work overall? we could update the guide with it.

adafruit2
Site Admin
 
Posts: 19377
Joined: Fri Mar 11, 2005 7:36 pm

Re: Make it Pulse in MakeCode

by V2man on Sun Nov 24, 2019 7:34 pm

You won't get an endorsement from me! Its too finicky and marginal. I don't think most people will have the patience to hold their finger for the period of time it takes to get the plot I posted. Every time I put in additional console blocks in Makecode to monitor another variable it stopped working. I did want to add a timer with the goal of getting BPM by counting peaks or bring out the samples[i] - mean to an oscilloscope. I have not learned how to do that with success. I wanted a secondary way of verifying I was getting a pulse rate. I also never figured out why the value of the outputs from CircuitPython version to the Makecode translation do not agree.
When Makecode is available for CPB I will revisit this to see if the 33% increase in CPU frequency makes it less touchy.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Please be positive and constructive with your questions and comments.