Teachable Machine

Teachable Machine

Train a computer to recognize your own images, sounds, & poses.

Hi Jonathan,

Glad to hear that you are interested in Tiny Sorter!

First off, you definitely don't need to be an expert in p5 or arduino to make the Tiny Sorter. We created it with anyone in mind.

As for microcontroller compatibility, Tiny Sorter right now is limited to those with a 32u4 processor. We recommend the Leonardo, but many other microcontrollers use this processor as well such as the Arduino Micro, Adafruit Trinket, etc.

As for the software, here are the three main steps to setup the code of the tiny sorter that I hope will address each of your questions:

1. Load the sketch onto the Arduino.

Here is the download link for the Sketch and WebUSB Library that will run on the Arduino. You will find the full installation instructions as well as download links to the same folders on the Tiny Sorter instructions site under the 'Connect it to your browser' section. (click the left and right arrows next to the video to scroll through videos of the different steps)

2. Train your model in Teachable Machine

Once training is complete, you will click 'Export Model', then 'Upload'. You will see a link appear underneath the 'shareable link' field, This is the link to your model you will paste into the p5 sketch.

3. Run the Tiny Sorter

Paste the model link into the p5 sketch, and connect the arduino through WebUSB. You won't need to install anything on your computer for WebUSB to work, just make sure to be running a recent version of Chrome.

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