Image for post
Image for post

Juggling Arduino Sensors With cocoOS


Image for post
Image for post

Let’s Build A Multitasking Arduino Device

    IF temperature > 27.0
OR humidity > 60.0
THEN send message
Image for post
Image for post

From https://github.com/lupyuen/send_altitude_cocoos/blob/master/main.cpp

Now Let’s Build It With cocoOS

    task_create(sensor_task, tempContext, 10, ...

From https://github.com/lupyuen/send_altitude_cocoos/blob/master/sensor.cpp

The Sensor Task Loop

Summarised from https://github.com/lupyuen/send_altitude_cocoos/blob/master/sensor.cpp

From https://github.com/lupyuen/send_altitude_cocoos/blob/master/sensor.cpp

Sending Messages To Tasks

From https://github.com/lupyuen/send_altitude_cocoos/blob/master/display.cpp

Image for post
Image for post

What’s A Semaphore?

Image for post
Image for post
From main.cpp and sensor.cpp in https://github.com/lupyuen/send_altitude_cocoos

Compiling The Arduino Code

#define CONFIG_ARTICLE1  //  Uncomment to support Article #1

Arduino IDE

Image for post
Image for post
Arduino IDE

Arduino Web Editor

Image for post
Image for post
Arduino Web Editor showing the source tree, source window and compiler log

Visual Studio Code with PlatformIO

Image for post
Image for post
Visual Studio Code + PlatformIO showing the source tree, multiple source windows and Serial Monitor
Image for post
Image for post

What’s Next?


Bonus Tip: Conserving Dynamic Memory By Using Flash Memory

Sketch uses 16732 bytes (51%) of program storage space. Maximum is 32256 bytes.Global variables use 1454 bytes (70%) of dynamic memory, leaving 594 bytes for local variables. Maximum is 2048 bytes.
Image for post
Image for post
Serial.print("This uses Dynamic Memory");Serial.print(F("This uses Flash Memory"));
Adapted from https://github.com/lupyuen/send_altitude_cocoos/blob/master/display.cpp

Coinmonks

Coinmonks is a non-profit Crypto educational publication.

Sign up for Crypto News

By Coinmonks

A newsletter that brings you week's best crypto and blockchain stories and trending news directly in your inbox, by CoinCodeCap.com Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Lup Yuen Lee 李立源

Written by

Techie and Educator in IoT 物聯網教師

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Lup Yuen Lee 李立源

Written by

Techie and Educator in IoT 物聯網教師

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store