Skip to main content

DueSTEM Tutorial

DueSTEM's InputProcessOutput mindset shines among Educators. You will quickly see how systems take inputs, process that input, to then take action on the outputs.

DueSTEM

While there are several coding options for DueSTEM, we will focus on MicroBlocks block-coding and on Python. Using other high-level languages, like JavaScript and .NET C#, is similar to Python.

CompareMicroBlocksPython
DifficultyVery EasyMedium to Advanced
StyleDrag-and-Drop blocksType coding
PC useOnly to code but runs standalonePC is needed to execute
LibrariesMicroBlocks libsDUELink standard libs
PopularityMostly SchoolsGlobal Use

MicroBlocks

Why should you use MicroBlocks:

  1. Easy to start.
  2. Easy to learn.
  3. Runs right on the hardware. Programs continue to run even if the computer was disconnected.
  4. Any changes on the designer surface show immediately on the device.

MicroBlocks

Before we get started, visit the Getting Started page to blink the STAT LED.

MicroBlocks

The MicroBlocks' page has full details if necessary.


Libraries

When MicroBlocks detects DueSTEM, an Edu focused-board, it automatically adds the DUELink Edu library. You can add it manually as well. It will also add the Tiny OLED library to help with display, plus Tone for making sounds.


Input

There are four inputs. All inputs are directly supported by the DUELink Edu lib.

FunctionDUELink Edu blockNotes
AccelerometerDueSTEM tiltPick x,y,z to read acceleration in one of the axis.
TemperatureDueSTEM Temperature (x10)Read temperature in celsius, multiplied by 10, 245 is 24.5 degrees.
Lightdue light level (0-1000)Read the ambient light intensity in the range of 0 to 1000, where 0 is very dark and 1000 is super bright.
ButtonsDueSTEM [left] buttonReturns the press status of one of the four buttons.

Process

This is where the "brain" needs to make some decisions. You will be using a lot of blocks from under the Control palette, such as if. This conditional block will also need some of the Operators blocks.


Output

The four outputs are also supported by libraries. The multicolor lightbulb is controlled by the DueSTEM bulb block. It uses the three primary RGB colors to make up any desired color.


Samples

These samples show some DueSTEM uses.

📽 VideoProject LinkFunctionality
videoDefault Project DemoThis is the default demo. Use buttons to move the spaceship left and right and up to shoot. Light and temperature show on the display. Use down to move a servo.
videoFeed Me!This demo uses the on-board accelerometer. You have 10 seconds to eat as many fruits as you can!
videoHearing TestHow good is your hearing? Hold the right button and see how far you can go.
videoColor SelectorWhat is your favorite color? Use the left button to pick one of the three primary colors (Red/Green/Blue) then use up and down to change the levels.

DueSTEM also includes a Downlink connector for Daisylinking other modules. A special library, called DUELink Daisylink is used to send commands to connected modules. The product pages of these connected modules include a Driver tab that shows what commands (functions) are provided by that individual module.

In this example, we will control Snowy, a smart snowflake!

tip

The Snowy module, or any other Daisylinked module, must be loaded with the official DUELink firmware. The MicroBlocks' firmware is only loaded on DueSTEM.

video

Load the Snowy Daisylink project to see how it works.


Python

DueSTEM's inputs and outputs are a great showcase of how Python can access the physical world.

Before we get started, visit the Getting Started page to learn how to blink the STAT LED using Python.

By now, you should know how to start the DUELink controller in Python to control hardware, duelink = DUELinkController(availablePort).

You now have 2 options to control DueSTEM's elements. You could use the provided Driver Script, which is the easier approach. There is a tab on DueSTEM Product page for the Driver API. For examples, there is Light() driver function that returns the light level.

That function can then be wrapped in Python.

def GetLight():
ret = int(duelink.Engine.ExecuteCommand("Light()"))
return ret

light = GetLight()

But wait, we have already made these wrappers! The Tethered Sample for Python tab on DueSTEM Product page has all wrappers and a loop to get you started. Here it is here to help you out:

PC Tethered Python Sample (click for code!)
Python Tethered Sample
loading...

The second option for controlling elements is by accessing the pins directly using the standard library. This option requires more understanding of the hardware but gives you further control. To start, you can use the Driver code and the schematics to help you in understanding what libraries or pins/functions are being used.

Let's use for example use Sweep() instead of Beep() to make laser sounds! From the driver's "beep" function, we can see that it uses pin 3 to play sounds.

# An example function from the driver script
fn Tunes(f,d)
Beep(3, f, d)
fend

The python program can now use pin 3 to make the laser sound! We do so by sweeping frequency from 8Khz to 4Khz with, volume going from 200 to 20, over 200ms. Now, repeat that 3 times and we have a sound effect!

def Laser():
duelink.Sound.Sweep(3,8000,4000,200,20,200)
duelink.Sound.Sweep(3,8000,4000,200,20,200)
duelink.Sound.Sweep(3,8000,4000,200,20,200)

Laser()

From here, you can extend any Python project with a physical-element reach. Visit the Projects page and filter Python for some ideas. Maybe you want to set the light bulb green when your favorite stock goes up. Or, perhaps make some sounds and show a message on the display a build fails!

tip

This page is about DueSTEM but don't forget that each product page includes a Python demo as well.