SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Movement & IMU category should be posted in this forum.
User avatar
By RBerliner
I have been attempting to load a simple sketch, Sinewave, an example from MegunoLink.

This sketch works just fine when loaded to an Uno. When I attempt to load it to the Razor, if "switches the COM port in the middle of the upload. Below is a fragment of the upload listing. No errors are reported in the compile.

Using library MegunoLink at version 1.22 in folder: C:\Users\RBerliner\Documents\Arduino\libraries\MegunoLink
"C:\\Users\\RBerliner\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-size" -A "C:\\Users\\RBERLI~1\\AppData\\Local\\Temp\\arduino_build_585125/Sinewave.ino.elf"
Sketch uses 26008 bytes (9%) of program storage space. Maximum is 262144 bytes.
Forcing reset using 1200bps open/close on port COM7
PORTS {COM1, COM2, COM3, COM7, } / {COM1, COM2, COM3, } => {}
PORTS {COM1, COM2, COM3, } / {COM1, COM2, COM3, } => {}
PORTS {COM1, COM2, COM3, } / {COM1, COM2, COM3, } => {}
PORTS {COM1, COM2, COM3, } / {COM1, COM2, COM3, COM8, } => {COM8, }
Found upload port: COM8
C:\Users\RBerliner\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0/bossac.exe -i -d --port=COM8 -U true -i -e -w -v C:\Users\RBERLI~1\AppData\Local\Temp\arduino_build_585125/Sinewave.ino.bin -R
Set binary mode
At the end it reports

done in 0.164 seconds

Verify 26268 bytes of flash with checksum.
checksumBuffer(start_addr=0x2000, size=0x1000) = ddcc
checksumBuffer(start_addr=0x3000, size=0x1000) = 765b
checksumBuffer(start_addr=0x4000, size=0x1000) = 23b7
checksumBuffer(start_addr=0x5000, size=0x1000) = 2554
checksumBuffer(start_addr=0x6000, size=0x1000) = bc4f
checksumBuffer(start_addr=0x7000, size=0x1000) = 79c4
checksumBuffer(start_addr=0x8000, size=0x69c) = 4214
Verify successful
done in 0.025 seconds
CPU reset.

When the sketch is loaded to a UNO, it spits out sine and cosine values. on the Serial Monitor.

On the Razor, there is nothing.

The Sinewave sketch is listed below. It is simple enough although maybe there is some reason I should not expect this to work.

/* **********************************************************************************************
* Example program to plot sine wave data on MegunoLink's Time Plot visualiser
* Visit
* for more information.
* ********************************************************************************************** */
#include "MegunoLink.h"

// For more information on installing the MegunoLink Arduino library check out our documentation
// ... tegration/

// You can download the MegunoLink Interface (.mlx) that goes with this example here
// ... newave.mlx

// Uncomment if you would like to use plotting channels
// TimePlot MyPlot("Waveforms"); //"Waveforms" = the taget plotting channel (remember to select this in megunolink)

TimePlot MyPlot; //no channel selected

void setup()

MyPlot.SetTitle("Sine and Cosine Function Waveforms");

// Set the plotting parameters. "Sinewave" = series name, Plot::Blue = line colour
// 2 = line width, Plot::Square = marker style
MyPlot.SetSeriesProperties("Sinewave", Plot::Blue, Plot::Solid, 2, Plot::Square);
MyPlot.SetSeriesProperties("Cosinewave", Plot::Red, Plot::Solid, 2, Plot::Square);

// Colours include
// Red, Green, Blue, Yellow, Black, Magenta, Cyan, White

// Markers include
// Square, Diamond, Triangle, Circle, Cross, Plus, Star, DownwardTriangle, NoMarker

// Line style
// Solid, Dashed, Dotted, DashDot, DashDotDot

#define HW_LED_PIN 13 // LED attached to pin 13

void blinkLED()
static bool ledState = false;
digitalWrite(HW_LED_PIN, ledState);
ledState = !ledState;

void loop()
double dY, dY2;
float seconds;
float frequency = 0.5; //Hz
float phase = 3.141/2;

seconds = (float)millis()/1000;

dY = sin(2 * 3.141 * frequency * seconds);
dY2 = cos(2 * 3.141 * frequency * seconds + phase);

//Send Data To MegunoLink Pro
MyPlot.SendData(F("Sinewave"),dY); // Sinewave = series name, dY = data to plot
MyPlot.SendData(F("Cosinewave"),dY2); // By wrapping strings in F("") we can save ram by storing strings in program memory


User avatar
By TS-Chris
I'm not familiar with MegunoLink so I don't know if there are some incompatibilities with it, but the first thing that jumps out at me is you're trying to print to Serial and that doesn't ouptut to the USB port on a SAMD21 based board like the Razor.

You're going to need to print to SerialUSB instead if you want to see output through the USB cable.

We don't have a guide that explains this for this specific board but you might want to checkout the serial section of the SAMD21 Mini/Dev breakout boards for an explanation how to use Serial on a SAMD based board.
User avatar
By TS-Mark
Hi RBerliner,

To answer your question about the COM ports, that is just how the SAMD21 works. The SAMD21 doubles as its own USB-to-Serial converter and programmer so when Arduino is forcing the board into bootloader mode, the COM port will change. Once the sketch has been uploaded, the board will reset and should go back to the default port.

As for the issues with your code, the most likely culprit is related to how the SAMD21 works with programmable SERCOM options. You most likely need to define which serial port you want to print on. The hardware serial port on the 9DoF Razor is Serial1. The Uno only has one hardware serial port so using Serial.print() requires no extra definition on the Uno. The Hookup Guide for our SAMD21 Mini and Dev Breakouts will go into this in some detail. We also have a guide for configuring the SERCOM ports on various SAMD21-based boards that will go into much more detail on modifying and using the full capabilities of the SERCOM options on the SAMD21.