Lesson 37 – Painting Different Shapes on the OLED Screen

What is OTTO DIY – Otto is completely open source, Arduino compatible, 3D printable robot which you can put together yourself. This is robotics and opensource at it’s best. The robot was designed by Camilloa Parra as a social impact mission to create an inclusive environment for all kids. Learn more about OTTO DIY and grab a kit at www.ottodiy.com.

Software Required : You will need either Otto Blockly or the Arduino IDE to work on this tutorial. Head over to the following page to learn how to get Otto Blockly or the Arduino IDE installed on your machine – https://learning.kidzcancode.com/lesson/lesson-03-programming-your-otto-robot/ . Once you have the tools installed, launch the relevant application i.e. Otto Blockly or the Arduino IDE and get started using the code shown below.

Uploading code to the Otto DIY Robot : To upload the code to the Arduino Nano (brain of your Otto DIY Biped Robot) you will need to make sure you have the Otto DIY robot connected to your laptop/desktop using the correct cable. Then select the right COM (Communication Port) and type of Arduino board using the drop down menus provided at the top of the screen. Once that’s sorted hit the “tick mark” icon to validate your code and make sure you do not see any errors pop-up. Finally hit the “right arrow” icon to have the code uploaded to the Arduino Nano housed within the Otto DIY robot.

Tutorial : As part of this tutorial you will load the relevant libraries, initialize all the servos, setup the OLED I2C device and display different shapes on the OLED screen.

See Otto Blockly code below.

See Arduino code provided below.

#include <PlayRtttl.hpp> // Requires you to have the PlayRtttl Arduino library installed 
#include <Adafruit_GFX.h> // Requires Adafruit GFX library installed #include <Servo.h> 
#include <Adafruit_SSD1306.h> // Requires Adafruit SSD1306 library installed 
//#include <Otto.h> // Otto libraries prevent rest of the LCD code from working, need to disable and use capabilities provided by Servo.h 
//Otto Otto; // Otto libraries prevent rest of the LCD code from working, need to disable and use capabilities provided by Servo.h 
#include "DHT.h" // Requires you to have the Adafruit DHT library installed
#include <Servo.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels
#define OLED_RESET  -1 // sharing Arduino reset pin
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LeftLeg 2 // left leg pin, servo[0]
#define RightLeg 3 // right leg pin, servo[1]
#define LeftFoot 4 // left foot pin, servo[2]
#define RightFoot 5 // right foot pin, servo[3]
#define Buzzer 13 //buzzer pin
DHT dht_1(10,DHT11); //Initializing DHT11 sensor on pin 10
int i = 0;
Servo servo_2;
Servo servo_3;
Servo servo_4;
Servo servo_5;
void setup() {
  //Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer);
  //Otto.home();
  servo_2.attach(2);  // Initializing servo 
  servo_3.attach(3);  // Initializing servo
  servo_4.attach(4);  // Initializing servo
  servo_5.attach(5);  // Initializing servo
  pinMode(8, OUTPUT); // Initializing Tx for Ultrasonic sensor
  pinMode(9, INPUT);  // Initializing Rx for Ultrasonic Sensor
  pinMode(A0, INPUT); // Initializing Touch Sensor Pin
  pinMode(A6, INPUT); // Initializing Sound Sensor Pin
  dht_1.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.display();
  delay(5*1000);
  Serial.begin(9600);
  playRtttlBlockingPGM(13,(char*)TakeOnMe);
}
void dance(){ // Function to be customized to change dance routines
    //Getting the servos to move
    //for(i = 0; i<= 180; i++){
    for(i = 30; i<= 140; i++){  
     servo_2.write(i);
     delay(100);
    }
    servo_2.write(90); //Set position back to 90 degress
    delay(3000);
    //for(i = 0; i<= 180; i++){  
    for(i = 30; i<= 140; i++){
     servo_3.write(i);
     delay(100);
    }
    servo_3.write(90); //Set position back to 90 degress
    delay(3000);
    for(i = 45; i<= 120; i++){
     servo_4.write(i);
     delay(100);
    }
    servo_4.write(90); //Set position back to 90 degress
    delay(3000);
    for(i = 45; i<= 120; i++){
     servo_5.write(i);
     delay(100);
    }
    servo_5.write(90); //Set position back to 90 degress
 delay(5*1000);    
}
void show_temp() {
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println("Let\'s measure Temp & Humidity");
    display.display();
    delay(4*1000);
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println("The Temp is");
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,10);
    display.println(dht_1.readTemperature());
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,30);
    display.println("The Hum is");
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,40);
    display.println(dht_1.readHumidity());
    display.display();
    delay(4*1000);
}
void loop() {
  if (digitalRead(A0)){  // Reading input from touch sensor
    display.clearDisplay();
    display.fillRect(5, 5, 70, 30,1);
    display.display();
    delay(5*1000);
    dance();  //Calling slow dance routine
    delay(5*1000);
    show_temp();
    delay(5*1000);
 }
}

Purchasing the OTTO DIY Robot : To learn more about the Otto DIY robot or purchase a off the shelf kit please head over to the OTTO DIY website at www.ottodiy.com. By purchasing the kit you will be supporting Camillo Parra and the rest of the OTTO DIY Robot team. At the OTTO DIY website www.ottodiy.com you also have the option to purchase the kit without the 3D printed parts, print the parts yourself using your own 3D printer at home.

For those interested in downloading the 3D models for printing using your own 3D printer, you will find a number of OTTO DIY robot re-mixes (3D print models) along with the original project at the Printables website (hosted by the guys who own Prusa). So head over to the 3D models hosted at Printables.com website to see all the different variants of the OTTO DIY robot listed there. If you are just wanting to download the parts for the basic Otto DIY Biped Robot then check out the following link at the main OTTO DIY Biped Robot page at the Prusa website.

For Makers, Creators & Innovators – If you are a maker, hacker and want to put together your own 3D printed robot using off the shelf components then check out this article at DIYODE – 2 Legged 3D Printed Robot. You can source all the components, parts listed above from Ebay/Amazon. If you do that, you are responsible for identifying and sourcing relevant parts, however if you purchase the kit from the OTTO DIY website www.ottodiy.com you will get quality parts including support from the OTTO DIY team.

Learn more about the OTTO Biped Project and join the OTTO DIY Robot community here – https://wikifactory.com/+OttoDIY/otto-diy  and here https://wikifactory.com/+OttoDIY/otto-diy-plus

Questions