Thanks for reaching out, and please feel free to ask further questions or update us on how your class or project goes.
Gautam Bose
-------------------------------------------------------------------------------------------------------------------------
Hi,
You can rename the classes to anything that you like and the tiny sorter will work, as long as the model you trained has three classes. The p5 sketch shouldn't need to be modified.
The p5 sketch talks to the arduino by sending an integer value that's either '1' or '2' according to what class the model detects. Class 3 does nothing since it is the empty class and we don't want the sorter to tip. The arduino reads this value from the Serial port and tips the servo to either side accordingly.
The arduino code could be modified to do anything when it receives these classifications, by changing what happens in the conditional statements.
if (Serial && Serial.available()) {
color[colorIndex++] = Serial.read();
if (colorIndex == 1) {
// Serial.flush();
// analogWrite(redPin, color[0]);
if (color[0] == 1) {
//if class 1 recieved do any arduino behavior here
}
else if (color[0] == 2) {
//if class 2 recieved do any arduino behavior here
}
while (Serial.available()) {
int throwaway = Serial.read();
Serial.write("Throwing away.\r\n");
}
Serial.flush();
colorIndex = 0;
}
}
To make things even easier to modify (for example to support more than three classes), I have created a very minimal p5 sketch that doesn't have any of the tiny sorter UI but instead a basic webcam preview of the TM model and the code to send classification values to Arduino. Check it out here
In this p5 sketch, you will paste in your model URL into the `model_url` variable at the top of sketch.js, and then use the conditional to send any number of class value/names to the arduino.
Also in the sketch.js file in p5, you will see this conditional on lines 65-82. You can change the class labels to match your TM model, and then add conditionals in the arduino sketch to listen for each different integer and do something different.
if (label === 'My Class Label 1') {
data_to_send[0] = 1;
}
else if (label === 'My Class Label 2') {
data_to_send[0] = 2;
}
else if (label === 'My Class Label 3') {
data_to_send[0] = 3;
}
... and so on
if (port != undefined) {
port.send(data_to_send);
}
----------------------------------------------------------------------------------------
I hope that this info is enough to get you started! Again, reach out with any other questions and good luck :)
Gautam Bose | Fiver vía Adecco | gbose@google.com | 760-642-9174