Alex JonssonJohan Risch
Published © MIT

Vizualise Arduino streams in the browser on your Mac

Reading data off an Arduino UNO via the serial port on a Mac computer, and rendering graphs/analytics in a jiffy in the browser.

IntermediateProtip1 hour214
Vizualise Arduino streams in the browser on your Mac

Things used in this project

Story

Read more

Code

Arduino sketch

C/C++
Example code for generating altering signals (square, sine, triangle waves), sent through the serial cable.
const float pi = 3.14159;

void setup() {
  Serial.begin(115200); // open the serial port at 115200 bps:
}

void loop() {
  static uint8_t pkt[8];
  
  static int i = 0;
  static int x = 0;
  static float y = 0;
  static uint8_t square = 60;
  static uint8_t height = -1; 
   
  y=20*sin(x*pi/180);   // calculate sine, transform deg->rad 

  pkt[0] = 0x55; // designated start byte
  pkt[1] = 0x00; // not in use
  pkt[2] = 0x00; // not in use
  pkt[3] = square+height*20; // square wave
  pkt[4] = 97+i; //sawtooth wave
  *((int16_t *)&pkt[5]) = (int16_t)(y); // sine wave
  pkt[7] = 0xAA; // designated stop byte
  
  i++;
  if(i>20)
    {
      i=0;
      height *=-1;
    }
  x = x+5;// increase the angle
  Serial.write(pkt,8);  // send package
  delay(10);
}

Credits

Alex Jonsson

Alex Jonsson

5 projects • 0 followers
Johan Risch

Johan Risch

3 projects • 0 followers

Comments