Seitaro IshikawaShinya Ishikawa
Published © CC BY-NC

Robot No.2

Robot No.2 is my summer project: a self-designed robot with moving arms and neck, built in Tinkercad, 3D-printed, and powered by M5Stack

BeginnerShowcase (no instructions)3 hours98
Robot No.2

Things used in this project

Hardware components

ESP32 Basic Core IoT Development Kit
M5Stack ESP32 Basic Core IoT Development Kit
I put Stack-chan on top so it can move like a real robot.
×1
M5Stack Unit 8servos
To control the servo motors.
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
For moving the arms and neck.
×1
Battery Holder, AAA x 4
Battery Holder, AAA x 4
×1
Stack-chan
×1

Software apps and online services

M5Stack UIFlow 2.0

Story

Read more

Custom parts and enclosures

arm

Sketchfab still processing.

leg

Sketchfab still processing.

body

Sketchfab still processing.

Code

Firmware

Python
import os, sys, io
import M5
from M5 import *
import m5ui
import lvgl as lv
from hardware import PWM
from hardware import Pin
import time
from hardware import I2C
from unit import Servos8Unit



page0 = None
switch0 = None
label0 = None
pwm19 = None
pwm27 = None
i2c0 = None
servos8_0 = None


import random

pitch = None
yaw = None
pulse = None
moving = None


def setup():
  global page0, switch0, label0, pwm19, pwm27, i2c0, servos8_0, pitch, yaw, pulse, moving

  M5.begin()
  Widgets.setRotation(1)
  m5ui.init()
  page0 = m5ui.M5Page(bg_c=0xffffff)
  switch0 = m5ui.M5Switch(x=92, y=79, w=132, h=66, bg_c=0xe7e3e7, bg_c_checked=0x2196f3, circle_c=0xffffff, parent=page0)
  label0 = m5ui.M5Label("label0", x=66, y=44, text_c=0x000000, bg_c=0xffffff, bg_opa=0, font=lv.font_montserrat_14, parent=page0)

  pitch = 80
  yaw = 70
  pwm19 = PWM(Pin(19), freq=50, duty=yaw)
  pwm27 = PWM(Pin(27), freq=50, duty=pitch)
  pulse = 1800
  moving = True
  switch0.set_state(lv.STATE.CHECKED, True)
  i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000)
  servos8_0 = Servos8Unit(i2c0, 0x25)
  servos8_0.set_mode(3, 0)
  servos8_0.set_mode(3, 1)
  page0.screen_load()


def loop():
  global page0, switch0, label0, pwm19, pwm27, i2c0, servos8_0, pitch, yaw, pulse, moving
  M5.update()
  yaw = random.randint(60, 80)
  pitch = random.randint(78, 82)
  pwm.duty(yaw)
  pwm.duty(pitch)
  time.sleep(1)
  for pulse in range(1600, 2001, 10):
    if not (switch0.has_state(lv.STATE.CHECKED)):
      break
    label0.set_text(str(pulse))
    servos8_0.set_servo_pulse(pulse, 0)
    servos8_0.set_servo_pulse(pulse, 1)
    time.sleep_ms(40)
  time.sleep(1.5)
  for pulse in range(2000, 1599, -10):
    if not (switch0.has_state(lv.STATE.CHECKED)):
      break
    label0.set_text(str(pulse))
    servos8_0.set_servo_pulse(pulse, 0)
    servos8_0.set_servo_pulse(pulse, 1)
    time.sleep_ms(40)
  time.sleep(1.5)


if __name__ == '__main__':
  try:
    setup()
    while True:
      loop()
  except (Exception, KeyboardInterrupt) as e:
    try:
      m5ui.deinit()
      from utility import print_error_msg
      print_error_msg(e)
    except ImportError:
      print("please update to latest firmware")

Credits

Seitaro Ishikawa
1 project • 2 followers
Shinya Ishikawa
1 project • 1 follower
A JavaScript guy who loves all the interface between humans and machines.

Comments