BeKindBe Kind.

Every day I practice actions around the two words “Be Kind”.  When I reflect at the end of the day, I realize there were interactions when I could have done better.  I will continue to practice.  However, unfortunately, I failed when I called out the tech person who was helping me at Sparkfun.  I apologize to that person and remove their name from the post.  It is not the person who I feel provided bad service, but rather “the Sparkfun system” that allowed poor service to happen.  Poor service can happen at any time to any of us by any company.  So this is just my recent experience.  But as I get older, I really want to support companies that not only care greatly about their employees, but truly care about their customers….

Next thing I’m going to try with the D1 and MicroPython is using a timer interrupt to take a reading every 30 seconds (as a test).  The “best” way I can think of doing this is using main.py but first sorting out ways of doing stuff in WebREPL.

Timers

I’m getting a better feel for MicroPython.  Since I’m not using a PyBoard, I don’t have access to what seems to be a more feature rich implementation of embedded python via the pyb module.  The pyb module is available to PyBoards.  I posted a topic in the MicroPython Forum to see if anyone knows of a PyBoard with an Arduino header I can connect the Grove Base Shield to.

Here is the response I got from my question:

NewImage

 This forum is SUPER helpful.  THANK YOU!

 It looks like I’ll be moving away from the Grove Base Shield…but for now seems to work.  We’ll see….

The Timer class is found in the machine module.  I found this post “Quick reference for the ESP8266”the most useful at getting the Timer to work the way I wanted.  

The MicroPython Documentation that I saw also refers to a TimerChannel class.  This method does not seem to be part of the Timer object implemented by the ESP8266 implementation of MicroPython.

 Here is a link to General information about the ESP8266 MicroPython port.

NewImage

This worked.  The periodic timer kept executing regardless of CTRL-C which makes sense.  To stop the timer I typed tim.deinit().  As I played around with the timer period, too short of a period made it difficult to time in tim.deinit() so I ended up copying this command into the copy/paste buffer and past into WebREPL as many times as it took before the command stuck :-).

The callback is a lambda function.  Let’s see…what if I put a callback function that reads and displays the sensor readings as well as defines the timer.  Then inits the timer within WebREPL? main.py:

from machine import Timer

from machine import UART

 

def takeReadings(uart):

    gasdata = bytearray(9)

    uart.write(b’\xFF\x01\x86\x00\x00\x00\x00\x00\x79′)

    uart.readinto(gasdata)  

    for value in gasdata:

        print(value)

if __name__ == ‘__main__’:

    uart = UART(0,9600)    

    t = Timer(1)

 

It didn’t work:

NewImage

after 3 seconds, takeReadings(uart) fired and the read buffer was zero’d out.

 I tried several different ways to get the callback to work. I’m thinking there is a disconnect between the hardware reception of RX data into registers and the transfer of the data into a buffer.  Perhaps the RX data that came into the registers is clobbered before the readinto(buffer) can execute.  I could spahlunk the ESP8266 code and such…but I’m thinking the ESP8266 on the Wemos D1 is “old”…do I really want to go down that path?  I see the options to be:

  • keep the code within main.py and use polling instead of interrupt.
  • buy a different MicroPython board – this means losing the ability to mount the Grove connectors…which more and more….
  • give up on MicroPython and load Arduino IDE onto the D1.
  • use an Arduino and get a separate wiFi BoB.
  • see if I can get the software serial library for MicroPython discussed here.
But …do we HAVE to leave MicroPython play land just yet?  Alright – not yet…ooh…shiny new object came in the mail – the relays! Time to give turning a relay on/off with MicroPython….YIPPEE!!!!!
 

 

Advertisements