Skip to main content

Workshop: Using Arduino with PEmbroider

2.

coming Arduino Code

The setup for the arduino code is nice and simple, we just need to read our value then print it to serial.

void setup() {
  Serial.begin(9600);
}


void loop() {
  int val = analogRead(A0);
  Serial.println(val);
  delay(100); 
}

3. Processing Code

There are quite a few things that we need to set up in this part of the code.

First, we need to import the correct libraries and create our Serial object and a variable to store the value we are reading (which has to be a string)soon...

import
processing.serial.*;
import processing.embroider.*;
PEmbroiderGraphics E;

Serial myPort;  // Create object from Serial class
String val = "0";

Within our setup() function, we can then find and connect to the correct serial port. The first line here with print all the names of the available ports,

  println(Serial.list());
  String portName = Serial.list()[6]; //change the 0 to a 1 or 2 etc. to match your port
  
  myPort = new Serial(this, portName, 9600);

x