OOSMOS Blink Example
1 Introduction
2 Blink on Various Platforms
2.1 Blink on Arduino
2.2 Blink on ESP8266
2.3 Blink on Galileo
2.4 Blink on MSP430
2.5 Blink on PIC32 Starter Kit
2.6 Blink on ChipKit
2.7 Blink on mbed
2.8 Blink on LightBlue Bean
2.9 Blink on Raspberry Pi
2.10 Blink on Trinket Pro
1 Introduction
2 Blink on Various Platf...
2.1 Blink on Arduino
2.2 Blink on ESP8266
2.3 Blink on Galileo
2.4 Blink on MSP430
2.5 Blink on PIC32 Starter...
2.6 Blink on ChipKit
2.7 Blink on mbed
2.8 Blink on LightBlue Bea...
2.9 Blink on Raspberry Pi
2.10 Blink on Trinket Pro
1 Introduction
2 Blink on Various Pla...
2.1 Blink on Arduino
2.2 Blink on ESP8266
2.3 Blink on Galileo
2.4 Blink on MSP430
2.5 Blink on PIC32 Start...
2.6 Blink on ChipKit
2.7 Blink on mbed
2.8 Blink on LightBlue B...
2.9 Blink on Raspberry P...
2.10 Blink on Trinket Pro
1 Introduction
2 Blink on Various P...
2.1 Blink on Arduino
2.2 Blink on ESP8266
2.3 Blink on Galileo
2.4 Blink on MSP430
2.5 Blink on PIC32 Sta...
2.6 Blink on ChipKit
2.7 Blink on mbed
2.8 Blink on LightBlue...
2.9 Blink on Raspberry...
2.10 Blink on Trinket P...

1 Introduction

This example is a scalable reimplementation of Arduino's standard Blink example. It demonstrates:
  • Blinking multiple LEDs all at different rates.
  • Threadless concurrency.
  • Use of the portable pin class.
  • Use of the reusable toggle class.

We actually have two versions of the toggle class in the Classes directory: one is implemented by transitioning back and forth between On and Off states. (See toggle.c_state.) The other implementation — the one used in this example — uses OOSMOS sync points. (See toggle.c.)

2 Blink on Various Platforms

Because each platform could have unique pins or header layouts, we show Blink on multiple platforms in the following sections.
The Arduino is a breeze to wire up. The pin assignments are printed on the Arduino circuit board and those are the numbers used to address them in the code. Not all boards are this straightforward.
Note that the red power jumper wire on the breadboard is not used. By convention, we wire each breadboard to connect the power rails to allow for intuitive part layouts.
Figure 1. Arduino Wiring Diagram
This is the main program for the Arduino.
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[GPLv2]
 
#includes...
 
static void SetupToggle(int Pin, int OnTimeMS, int OffTimeMS)
{
pin * pPin = pinNew(Pin, pinOut, pinActiveHigh);
toggleNew(pPin, OnTimeMS, OffTimeMS);
}
 
extern void setup()
{
SetupToggle(13, 2000, 2000);
SetupToggle(12, 100, 100);
SetupToggle(11, 50, 1500);
}
 
extern void loop()
{
oosmos_RunStateMachines();
}
BlinkExample.ino - Blink for Arduino
The ESP8266 ESP-01 is an exciting board. It's very inexpensive, has a full-fledged 80 MHz processor, about 45K of user available RAM, and it has WI-FI capability so it's ideal for connecting devices to the Internet.
We hope to use this processor more and more for OOSMOS-based IOT projects.
Notes:
When uploading from the Arduino IDE to the ESP8266:
  • The RST pin of the ESP8266 is connected to the DTR pin of the USB-to-UART module (see figure 2). This is called auto-reset; you need only press the PROG button to upload new code.
  • You must press and hold the PROG button during upload. You can wait until you see the Uploading message before pressing it. Leave it pressed until you see the Done uploading message. When you release the button, the board should immediately run your code.
  • Make sure the serial monitor window is closed. If you leave it open, the board can be programmed but the ESP8266 will not reset properly when it's done uploading.
Figure 2. ESP8266 Wiring Diagram
This is the main program for Blink on ESP8266. Because there is only one LED on board, we blink that.
Note that because the ESP8266 has sleep capability, we demonstrate it here. (See lines 49-50.)
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[GPLv2]
 
#includes...
 
//
// It is unclear which #include file holds these prototypes. We declare
// them here for now.
//
extern "C" bool system_deep_sleep_set_option(int option);
extern "C" void system_deep_sleep(int);
 
static void SetupToggle(int Pin, int OnTimeMS, int OffTimeMS)
{
pin * pPin = pinNew(Pin, pinOut, pinActiveHigh);
toggleNew(pPin, OnTimeMS, OffTimeMS);
}
 
extern void setup()
{
SetupToggle(BUILTIN_LED, 2000, 100);
}
 
extern void loop()
{
oosmos_RunStateMachines();
 
system_deep_sleep_set_option(4);
system_deep_sleep(10*1000); // in uS...
}
BlinkExample.ino - Blink for ESP8266
The Galileo uses standard Arduino pin designators, so the main program is identical to Arduino's main program.
We should mention that, although we were able to illuminate the LEDs on the Galileo, the maximum amount of current we were able to draw from the digital output pins was only about 1 mA, not the 10 mA specified in the data sheet. This characteristic seems to be unique to the Galileo. If anyone knows why that might be, we'd love to hear from you.
Figure 3. Galileo Wiring Diagram
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[GPLv2]
 
#includes...
 
static void SetupToggle(int Pin, int OnTimeMS, int OffTimeMS)
{
pin * pPin = pinNew(Pin, pinOut, pinActiveHigh);
toggleNew(pPin, OnTimeMS, OffTimeMS);
}
 
extern void setup()
{
SetupToggle(13, 2000, 2000);
SetupToggle(12, 100, 100);
SetupToggle(11, 50, 1500);
}
 
extern void loop()
{
oosmos_RunStateMachines();
}
BlinkExample.ino - Blink for Galileo
The Fritzing tool does not have the MSP430F5529 LaunchPad part that we have, so we created custom female header parts, labeled as they are on the MSP430F5529, in order to guide you graphically through the wiring process.
Figure 4. MSP430 Wiring Diagram
The MSP430 board has specialized pin addressing. (See lines 29-31.)
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[GPLv2]
 
#includes...
 
extern void setup()
{
pin * pLedSlow = pinNew(P1_2, pinOut, pinActiveHigh);
pin * pLedFast = pinNew(P1_3, pinOut, pinActiveHigh);
pin * pLedPing = pinNew(P1_4, pinOut, pinActiveHigh);
 
toggleNew(pLedSlow, 2000, 2000);
toggleNew(pLedFast, 100, 100);
toggleNew(pLedPing, 50, 1500);
}
 
extern void loop()
{
oosmos_RunStateMachines();
}
BlinkExample.ino - Blink for MSP430
We demonstrate two boards that use the PIC32 processor: the PIC32 Starter Kit directly from Microchip, and the Arduino-compatible ChipKit board. This example uses the PIC32 Starter Kit. Because there are already three LEDs on the board that we can address, we don't need to use the I/O Expansion board, so there is no external wiring required.
Figure 5. PIC32 Starter Kit Board
Using the PIC32 environment from MPLAB, we need to specify certain #pragmas to configure the chip. (See lines 27-28.)
Additionally, the PIC32 that uses PLIB from Microchip has specialized pin addressing. (See lines 34-36.)
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[GPLv2]
 
#includes ...
 
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
 
extern int main(void)
{
oosmos_ClockSpeedInMHz(80);
 
pin * pRED = pinNew(IOPORT_D, BIT_0, pinOut, pinActiveHigh);
pin * pYELLOW = pinNew(IOPORT_D, BIT_1, pinOut, pinActiveHigh);
pin * pGREEN = pinNew(IOPORT_D, BIT_2, pinOut, pinActiveHigh);
 
toggleNew(pRED, 2000, 2000);
toggleNew(pYELLOW, 100, 100);
toggleNew(pGREEN, 50, 1500);
 
while (true)
oosmos_RunStateMachines();
}
main.c - Blink for PIC32
Unlike an Arduino Uno, the ChipKit has two rows of headers, so be careful while wiring.
Figure 6. Blink on ChipKit
Because the ChipKit is Arduino pin compatible, we can use the exact same main program as we did for the Arduino example.
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[GPLv2]
 
#includes...
 
static void SetupToggle(int Pin, int OnTimeMS, int OffTimeMS)
{
pin * pPin = pinNew(Pin, pinOut, pinActiveHigh);
toggleNew(pPin, OnTimeMS, OffTimeMS);
}
 
extern void setup()
{
SetupToggle(13, 2000, 2000);
SetupToggle(12, 100, 100);
SetupToggle(11, 50, 1500);
}
 
extern void loop()
{
oosmos_RunStateMachines();
}
BlinkExample.ino - Blink for ChipKit
This example has been tested using mbed.com's web-based developer program workspace targeting the LPC1768 and FRDM-K64F boards. We show the LPC1768 board here.
Because the mbed LPC1768 board has four onboard LEDs, we use them all.
Plug your mbed device into your computer via USB. A new drive letter will appear. Let's say it comes up as the G: drive.
Upload the mbed blink project files to mbed.com's online workspace and select "compile", which will initiate a download of the resulting bin file. Drag that file to the volume of the device, e.g. the G: drive, and then press the reset button on the device. The four LEDs on the board should now blink at the rates specified in the main program.
Figure 7. MBED Board
The mbed board has specialized pin addressing. (See lines 29-32.)
1
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[GPLv2]
 
#include "oosmos.h"
#include "pin.h"
#include "toggle.h"
 
extern int main()
{
pin * pLED1 = pinNew(LED1, pinOut, pinActiveHigh);
pin * pLED2 = pinNew(LED2, pinOut, pinActiveHigh);
pin * pLED3 = pinNew(LED3, pinOut, pinActiveHigh);
pin * pLED4 = pinNew(LED4, pinOut, pinActiveHigh);
 
toggleNew(pLED1, 5000, 2000);
toggleNew(pLED2, 100, 100);
toggleNew(pLED3, 500, 500);
toggleNew(pLED4, 50, 1500);
 
while (true) {
oosmos_RunStateMachines();
}
}
 
main.cpp - Blink for mbed
LightBlue Bean is essentially an Arduino with BlueTooth Low Energy (BLE) capability built in.
The pin assignments are different than on an Arduino, so this is a slightly specialized main program. See the example in Snippet 1, below.
Note that the photo shows a set of female headers soldered onto the board. The board does not come with these; we added them.
Because in this example we are going to drive three (approximately) 20 mA LEDs, we cannot use the low-current 3V coin battery (approximately 15 mA total maximum), so we borrow power from the regulated 3.3V power supply of a separate USB-powered Arduino.
Figure 8. LightBlue Bean Board
The LightBlue Bean board has specialized pin addressing. (See lines 29-31.)
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[GPLv2]
 
#includes...
 
extern void setup()
{
pin * pLedSlow = pinNew(1, pinOut, pinActiveHigh);
pin * pLedFast = pinNew(2, pinOut, pinActiveHigh);
pin * pLedPing = pinNew(3, pinOut, pinActiveHigh);
 
toggleNew(pLedSlow, 2000, 2000);
toggleNew(pLedFast, 100, 100);
toggleNew(pLedPing, 50, 1500);
}
 
extern void loop()
{
oosmos_RunStateMachines();
}
Snippet 1. BlinkExample.ino - Blink for LightBlue Bean
For Raspberry Pi, we use the Wiring Pi library, which gives us a familiar single number pin description just like Arduino. Wiring Pi is not part of our distribution, so you'll have to download and build it yourself.
For Wiring Pi pin numbers for the various Raspberry Pi models, go here.
Figure 9. Raspberry Pi Wiring Diagram
This is the main program for the Raspberry Pi. Note the specialized pin addressing on lines 29-31.
1
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[GPLv2]
 
#includes ...
 
extern int main(void)
{
pin * pRED = pinNew(0, pinOut, pinActiveHigh);
pin * pYELLOW = pinNew(2, pinOut, pinActiveHigh);
pin * pGREEN = pinNew(3, pinOut, pinActiveHigh);
 
toggleNew(pRED, 2000, 2000);
toggleNew(pYELLOW, 100, 100);
toggleNew(pGREEN, 50, 1500);
 
while (true) {
oosmos_RunStateMachines();
oosmos_DelayMS(50);
}
}
main.c - Blink for Raspberry Pi
The Blink code for the Trinket Pro is identical to the code for the Blink for Arduino application.
Copyright © 2014-2016  OOSMOS, LLC