Using the Dash class

The Dash provides more features than a regular Arduino board. To give you easy access to Dash-specific features, we have provided a Dash class. We’ll be posting some in-depth tutorials on using these features, but here is a quick overview of what is available.

Initializing

To get the Dash class started, in your setup() function, call

Dash.begin();

Controlling the LED

The basics:

Dash.setLED(on);  //turn on if on is true, off if false
Dash.onLED();     //turn on the LED
Dash.offLED();    //turn off the LED
Dash.toggleLED(); //off->on or on->off

To blink the LED:

Dash.pulseLED(on_time, off_time);

The LED will turn on for on_time milliseconds, turn off for off_time milliseconds, then repeat. Stop the blink by calling one of the other LED functions.

Battery

You can get state of the battery using:

Dash.batteryPercentage();
Dash.batteryMillivolts();

These functions will only give you valid battery values if your board is configured for battery operation via the jumper settings.

Sleep

Dash.snooze(milliseconds);
Dash.sleep();
Dash.deepSleep();
Dash.shutdown();

You can use snooze() as a lower-power replacement for the Arduino delay() function. The sleep() function will stay in sleep until an interrupt occurs (such as a configured IO interrupt or a serial character received). The deepSleep() function saves more power, but can only wake up using specially configured IO interrupts (see the WKUP column in the Operation Manual). The shutdown() function works the same as the deepSleep() function, except that on wake up the processor resets and your program will start in the setup() function again. The upcoming sleep tutorial will have more details.

IO Interrupts

As of version 0.7.2 for Arduino, the IO interrupt functionality has been changed to use the attachInterrupt() function. This should provide better compatibility with other Arduino sketches and libraries.

OBSOLETE
To setup IO interrupts, create a callback function in your Arduino sketch that will be called when an IO interrupt occurs. It can have any name, but it needs to return void and take a single uint32_t parameter.

void handle_interrupts(uint32_t io)
{
  if(IO_MATCH(io, D01))
  {
    //Do something because D01 changed
  }
}

In your setup() function, set this function as your callback:

Dash.setIoCallback(handle_interrupts);

Now enable any IO interrupts you want to use.

Dash.enableIoInterrupt(D01, IO_INT_FALLING); //interrupt on falling edge (HIGH to LOW) of pin R03
Dash.enableIoInterrupt(D02, IO_INT_RISING); //interrupt on rising edge (LOW to HIGH) of pin R04
Dash.enableIoInterrupt(D03, IO_INT_RISING | IO_INT_FALLING); //interrupt on any change to pin R05
Dash.disableIoInterrupt(D01); //turn off the interrupt

The upcoming IO interrupts tutorial will have more details.

2 Likes

I’ve also discovered by accident that it seems you can now Serial.print in place of SerialUSB.print. Both forms are working on my end, and it’s a welcome addition – really helps us use our old Arduino (non-Dash) code.
Thanks!

@MichaelM: Yes, Serial now is equivalent to (shorthand for) SerialUSB

Thanks, Pat!

New issue: It appears that the maximum Serial.print() length in Dash is shorter than with Arduino HW. For example, the following line prints fine on a Genuine Uno, but is truncated on Dash, either via Serial.print() or Serial.print(F()).

Boy, oh, boy, this is a a test of the Arduino Serial!!  We're serial printing a really long line here!  Wow!  Still going!

Serial output when long output is used, is not only truncated, but it causes pretty severe garbling of the serial output with Dash for the next several statements after the long one. This is definitely not any kind of showstopper issue, but certainly something that took a few scratches of the head to figure out – especially coming from the classic Arduino world, when long print lines – or in my current case, very long strings to populate a number of fields on the thingspeak cloud – caused my cere caused my serial debug output to look downright bizarre.

@MichaelM Thanks for posting that question. That is definitely a bug and the fix will be included in our next Arduino release. It looks like strings of size 64 bytes or smaller work okay, but after that things do get goofy. I don’t have a date for the next release yet, but as soon as we do I’ll let you know.

Thanks, Erik – glad it’s not just me… No worries in the meantime - I’ll just be more economical with my statements!

Great to see that you’ve been able to design deep sleep functions. And turn off the led to save power as well

Hmm, I get compiler errors when I try to use this code, saying that “on” and “off” are not declared.

Also, if I try to use any of these functions (or at least the LED [using true/false instead] or snooze functions), the Dash stops showing available as a serial port, so I can’t use serial monitor, and I don’t think my firmware is still running. Am I doing something terribly, horribly wrong?

@SeanMcTex,

The setLED function takes a boolean value as the single argument. So you can do this

Dash.setLED(true); //turn on
Dash.setLED(false); //turn off
bool led = true;
Dash.setLED(led); //turn on 
led = false;
Dash.setLED(led); //turn off

To use any of the Dash class functions, make sure you call

Dash.begin();

in your setup function. And make sure you are calling

Serial.begin();
//or
SerialUSB.begin();

in setup() also if you want to activate the USB serial port.

From your description, I’m guessing Dash.begin() will get you running again.

Welp, you put your finger on it. I had dutifully read the instructions and included Dash.begin(), but my logic obscured the fact that I was making other calls to Dash before that. When done in order, they work pretty well. :slight_smile:

How is it that a sketch does not have to have a #include for the Dash class?

The Dash class is part of the Arduino core for the Dash, so an additional library isn’t required.

Trying to do a 3 minute sleep with the Dash, but this will not compile:

Dash.sleep(180000);

error:

candidate expects 0 arguments, 1 provided
exit status 1
no matching function for call to ‘DashClass::sleep(int&)’

What am I leaving out? Thanks…

Dash.begin(); is in my setup(void)

ah… nevermind, I need snooze, not sleep

How do I put the dash to deep sleep and use timer to wake it up (let’s say in 20 minutes)?

Take a look at the sleep functions up above in the first post

Is it possible to use a timer to act as an interrupt instead of a Digital Interrupt (e.g Button)?

Ah, I see. That’s not done yet, but is on the roadmap. Probably done next week.

Hello. Is there an official release date for this? As I need to use it for a major project.

Hey @tristy,

We’re working on some bugs for a next firmware release, and this is coming up soon after that. Will try to keep you posted.

Thanks,
PFW