Notes from Dr. Bruce’s demo on MicroPython 2/9/2019 at RSSC Meeting rssc.org https://store..micropython.org and https://docs.micropython.org/en/latest/pyboard/tutorial/index.html He uses PuTTY for Windows. But another terminal emulator would work. The OS is MicroPython. When you plug in the board to your computer, it looks like a thumb drive. main.py is the most important program on the board, it’ll run that program. If there is a main.py on the SD card on the board, it will run that instead. Do not play with boot.py You can edit main.py with any text editor. Dr. Bruce uses Spider, which is the editor that comes with Anaconda. From the terminal widow, ctrl C wakes up the card. The window that comes up is not from main. It is the OS, which is Python. Type ?, hit return, and you’ll get 0.3333333 Now try this program: g = pyb.Pin(pyb.Pin.board.X1, pyb.Pin.OUT) This is the program. It has not yet been saved. We are communicating directly with the board via the terminal emulator. This program defines the Python pin.. We call it g here. He plugged a LED and resistor to X1. Now by typing the below, we can turn it on or off. g..on() g.off() High or low will also work. g.high() g.low() If we were to type g.ogg(), it shows an error. The tutorial shows lots of examples. servo1 = pyb.Servo(2) Servor is connected to pin 2. servo1.angle(45) servo1.angle(-60) servo1.angle(50, 1000) the second argument is how many ms it takes to get there. servo1.angle() this tells us what location it’s at This board does not have as many libraries or support as an Arduino. There isn’t a built in library for sonar (ultrasonic sensor). So, he Googled it, and found someone who posted code. This guy created code for a class for ultraconic. class Ultrasonic: t pin (trigger) e pin (echo) Maybe 30 lines of code. Br Bruce stored this in a file called Ultrasonic.py To use it, we write the following program: import pyb import ultrasonic # setting pins to acomodate Ultrasonic sensor #sensor needs 5V and ground to be connected to pyboard’s ground sensor1_echoPin = pyb.Pin.board.X3 sensor1_echoPin = pyb.Pin.board.X4 # creates Ultrasonic object using the above pin config sensor1 = ultrasonic.Ultrasonic(sensor1_trigPin, sensor1_echoPin) def print_sensor_values(): distance1 = sensor1.distance_in_cm() print(“Sensor1 (Metric System)”, distance1, “cm”) while True: print_sensor_values() pyb..delay(1000) He saved this as main.py on the card along with ultrasonic.py on the card. Restart PuTTY, and it runs continuously showing distance. while True: g.on() pyb.delay(500) g..off() pyb.delay(500) makes the LED blink.. Save that in RAM, then when you power up the board, the LED blinks. ==== Unrelated, he now shows us a radar motion sensor. Radar is good at detecting metal and water. Humans are mostly water The sensor picks up things as far away as 10 ft. It picks up a sphere. It can see a human through wood. A current limiting resistor is built onto the board, so you can take an LED straight from the pin to ground. He uses this for his robot to tell if there is a person in the room. “If there is motion, it must be a human. If there is no motion for X minutes, maybe I should move to a different room to see if someone is in there.” $2. The board is RCWL-0516 It can be found on eBay or Amazon.