Links for Smart Objects class at ESNE 3rd March 2023
Setup Ex
Basics of Electronics
- Electronics 101
- Digital Logic
- LEDs
- Capacitors
- Breadboard Basics
- Wires
- What is a circuit
- Circuit simulator used in the lecture
Arduino
- Arduino Learning Video Tutorials
- Arduino Learning Text Tutorials
- Arduino Documentation
- Neopixel
- Fritzing circuit building
- Machine Learning to Arduino template
Code
Basic Serial
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(8,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available() > 0)
{
char inByte = Serial.read();
if (inByte == '0')
{
digitalWrite(8, LOW);
}
else if(inByte == '1')
{
digitalWrite(8, HIGH);
}
}
}
Serial communication with machine learning models
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(8, OUTPUT);
pinMode(9,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0){
String rcvdSerialData = Serial.readStringUntil('\n');
Serial.println(rcvdSerialData);
if(rcvdSerialData=="0")
{
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
}
else if(rcvdSerialData=="1")
{
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
}
else
{
digitalWrite(9,LOW);
digitalWrite(8,LOW);
}
}
}
Serial communication with machine learning models and neopixel
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 12 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pixels.begin();
}
void loop() {
// Set all pixel colors to 'off'
// put your main code here, to run repeatedly:
if(Serial.available() > 0){
String rcvdSerialData = Serial.readStringUntil('\n');
Serial.println(rcvdSerialData);
if(rcvdSerialData=="0")
{pixels.clear();
pixels.setPixelColor(0, pixels.Color(0, 150, 0));
pixels.setPixelColor(1, pixels.Color(0, 150, 0));
pixels.setPixelColor(2, pixels.Color(0, 150, 0));
pixels.setPixelColor(5, pixels.Color(0, 150, 0));
pixels.show();
}
else if(rcvdSerialData=="1")
{pixels.clear();
pixels.setPixelColor(2, pixels.Color(0, 150, 0));
pixels.show();
}
else
{
pixels.clear();
pixels.setPixelColor(1, pixels.Color(150, 150, 0));
pixels.show();
}
}
}