Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Created by Franck Albinet with source available here. Also presented by NSRC at APRICOT 2018.

Introduction

In this example, we will create and deploy the proverbial 1st app, “Hello, world!” to a Pycom device. Because the board does not have a display, we will use the USB connection between the board and the development PC to switch on and off an LED. In the simplest terms, a Light-Emitting Diode (LED) is a semiconductor device that emits light when an electric current is passed through it. LEDs are described as solid-state devices. The term solid-state lighting distinguishes this lighting technology from other sources that use heated filaments (incandescent and tungsten halogen lamps) or gas discharge (fluorescent lamps). Different semiconductor materials produce different colors of light.

...

Let's first operate the LED using the terminal interface. From the command line, enter:

Code Block
languagepy
linenumberstrue
import pycom
pycom.heartbeat(False) 
pycom.rgbled(0xFF0000)

The first line tells the system that you will use the pycom library. This library includes the utilities necessary to operate the specific pycom hardware. The second line tells the system NOT to use the heartbeat functionality of the LED. In normal operations, the LED will blink with a blue color every second to show that the device is running properly. The third line tells the system to switch on the LED with a xxx color. The color code is the following (with the first six characters showing the Red Green Blue components, in exadecimal format):

...

If you want your code to be permanently stored on the board, you need to open the LED directory and sync it to your board.

Code Block
languagepy
linenumberstrue
### boot.py

...



from machine import UART
import os
uart = UART(0, 115200)
os.dupterm(uart)



The boot.py file should always start with following code, so we can run our python scripts over Serial or Telnet. Newer Pycom boards have this code already in the boot.py file.

...

  • line 1: we import from the machine module the class UART (duplex serial communication bus)
  • line 2: we import the os module (basic operating system services)
  • line 3: we create an UART object (initalized with bus number=0 and baudrate=115200 - the clock rate)
  • and finally pass it to the dupterm method of the os module in order to make the REPL possible via Atom editor for instance.
Code Block
languagepy
linenumberstrue
main.py

...


import pycom
import time
pycom.heartbeat(False)
for cycles in range(10): # stop after 10 cycles
    pycom.rgbled(0x007f00) # green
    time.sleep(5)
    pycom.rgbled(0x7f7f00) # yellow
    time.sleep(5)
    pycom.rgbled(0x7f0000) # red
    time.sleep(5)

You should see the LED light up for five seconds at a time, in green, yellow and red. After the sequence has gone through ten cycles, the system will stop and the LED will remain red.

...