Misty Lessons
  • Misty Lessons
    • 📖Welcome to Misty Lessons
    • 📚Get to know your Misty
    • 📲Connect to Misty
    • 👩‍💻Misty Studio
    • 🖥️Desktop Environment
    • ⬆️Update your Misty
    • 👥Projects
  • Blockly
    • 🧩Blockly Lessons
      • 🤸Lesson 1: Movement
      • 🎶Lesson 2: Voice and Sound
      • 🎭Lesson 3: Expressions
      • 🎥Lesson 4: Robot Cinema
      • 🛠️Lesson 5: Events
      • ☺️Lesson 6: Face recognition
      • 🔢Lesson 7: Variables and Functions
      • 💬Lesson 8: NLP
    • 🏫Blockly projects
  • Blockly Elements
    • ⚛️Misty Blocks
      • Movement
      • Speech
      • Audio
      • Vision
      • Events
      • Miscellaneous
      • NLP
      • System
    • 🔁Basic Blocks
      • Logic
      • Loops
      • Math
      • Text
      • Lists
    • 🅰️Advanced Blocks
      • Variables
      • Functions
  • Python
    • 🐍Python Lessons
      • 🦿Lesson 1: Loco-motion
      • 🤖Lesson 2 : Build a character
      • 🧠Lesson 3: Create memories
      • ⚒️Lesson 4: Event skills
      • 👀Lesson 5: Expand awareness
      • 🔗Lesson 6: Compact code
      • 🗣️Lesson 7: Start a conversation
  • Python Elements
    • 🐸Misty Python API
      • Motion and Mobility
      • Display and LED
      • Record Assets
      • Change/Remove Assets
      • Stream Assets
      • Get Assets
      • Events
      • Sensor Events
      • Speech and NLP
      • Arduino Backpack
      • System
      • Slam
    • 📗Python Definitions
  • Python Projects
    • 🔮MistyGPT
    • 🚨Misty Intruder Alert
    • 📺Conference Assistant
    • 🏷️QR code detector
    • 🕵️‍♂️Misty follow human
    • 👋Misty wave back
    • 🖲️Misty OA
    • 🌐Get weather
    • 🚚Misty Delivery
    • 🫂Motivational Misty
    • 🖼️Misty Museum Guide
    • 🎃Who for Halloween
  • ARDUINO
    • ♾️Arduino Backpack
    • 🦎Arduino
    • 🔧Arduino Lessons
      • 🔌Arduino to Misty
      • ➕Misty to Arduino
  • ARDUINO PROJECTS
    • 🛠️Misty Tracker
    • 🦾Misty Arm
  • Community Projects
    • 🌤️Misty weather forecaster
  • HARDWARE EXTENSION
    • ⚙️Arduino breadboard support
    • 🦾Misty arm
    • 🥤Tin holder
  • Resource Database
    • 📁Image files
    • 📁Audio files
    • 📁Languages
    • 📁Known objects
    • 📁NLP Actions
    • 📁Action Commands
    • 📁ChatGPT PDF files
    • 📁AR Tag Dictionary
    • ⚙️Technical Specifications
Powered by GitBook
On this page
  • Materials
  • Arduino Circuit
  • Arduino Code
  • Misty Code
  1. ARDUINO
  2. Arduino Lessons

Arduino to Misty

In this project, you will use Arduino to trigger Misty to change the colour of her chest LED.

Last updated 8 months ago

Materials

  • Misty’s Arduino backpack

  • 2 buttons

  • 2 LEDs

  • 2 resistance 330 Ω

  • 2 resistance 10 kΩ

  • Some wires of different lengths.

Arduino Circuit

Arduino Code

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP); 	//pin green button
  pinMode(3, INPUT_PULLUP); 	//pin blue button
  pinMode(10, OUTPUT);      	//pin green LED
  pinMode(11, OUTPUT);      	//pin blue LED
}

void loop() {
  int pushedg = digitalRead(2); //green button
  int pushedb = digitalRead(3); // blue button

  if (pushedg == LOW){		// green button pressed condition
    digitalWrite(10, HIGH);	// green LED on
    Serial.println("green");	// write "green" in the serial
  } else {
    digitalWrite(10, LOW);	// green LED off
  }
  
  if (pushedb == LOW){		// blue button pressed condition
    digitalWrite(11, HIGH);	// blue LED on
    Serial.println("blue");	// write "blue" in the serial
  } else {
    digitalWrite(11, LOW);	// blue LED off
  }
  delay(200);			// wait for 200ms
}

The Arduino code is composed of two parts: the void setup and the void loop. The first one will run only once at the beginning and here you set all your variables. The second part will run in a loop until stopped.

In this void setup, you open the serial and set the pins you’ll use in this project. In the void loop, you associate the pins to our buttons and then we set two conditions:

If the green button is pressed you’ll turn on the green LED on the Arduino board and you will write in the serial the word “green” if this doesn’t happen the green LED will be off. It happens the same with the blue button as you can read in the code. At the end, we insert a pause in order not to send too many signals to Misty.

Misty Code

from mistyPy.Robot import Robot
from mistyPy.Events import Events

misty = Robot("your_robot_IP_address")

def msg(data):
    print(data)
    if data["message"]["message"] == "green":
misty.change_led(0, 255, 0)
         if data["message"]["message"] == "blue":
misty.change_led(0, 0, 255)

misty.register_event(event_name="serial_message_event", event_type=Events.SerialMessage, callback_function=msg, keep_alive=True)
misty.keep_alive()

To allow Misty to read in the Serial you need to build an event, so you can import the usual libraries that Misty uses to register events. Then we create the robot and the function that will be called with the event.

In this function we read the serial message and if the condition is verified Misty will complete the function. If we press the green button, Arduino will write “green” in the serial and Misty will register “green” as message from the serial port, so she’ll act as shown in the function.

🔧
🔌
It may seem in this scheme that the buttons are not fully connected but in your breadboard, you can close the pins a bit. You can use the same scheme with Arduino UNO or the arduino Backpack