James Martel
Published © GPL3+

What Do I Build Next? A Pico-ATMegaZero BOT part 1 of 2

I was looking for another BOT to build and then two new SBC's were announced or was it three SBC's? ATMegaZero ESP32-S2

IntermediateFull instructions provided4 hours699
What Do I Build Next? A Pico-ATMegaZero BOT part 1 of 2

Things used in this project

Hardware components

Raspberry Pi RPi PICO RP2040
×1
ATMegaZero and ATMegaZero-ESP32-S2 by Espinallabs.com
×1
L298N Motor Driver
×2
L9110S Motor Driver
×2
Adafruit 48mm Right Mecanum wheels
×2
Adafruit 48mm Left Mecanum wheels
×2
Adafruit metal geared DC motors
×4
Adafruit D motor mounting brackets
×4
PCA9685 16 Channel I2C PWM controller
×1
5 VDC buck convertor USB
×1
5 VDC buck convertor Micro
×1
Pololu Robot base expansion plate
×1
18650 battery holder with ON/OFF switch
×2
18650 battery 4000 maH
×4
battery charger multi-analyzer
×1
opto speed encoders
Not used in this initial build
×4
opto speed encoders2
Not used in this initial build
×4
4 wheeled robot chassis with mecanum wheels
This was used with the ATMegaZero32 build
×1

Software apps and online services

Arduino IDE
Arduino IDE
Thonny IDE for Windows 10
Microsoft Notepad text editor
MicroPython
MicroPython
Circuitpython

Hand tools and fabrication machines

small Philips screwdriver
Wire Cutter / Stripper, Self Adjust
Wire Cutter / Stripper, Self Adjust
adjustable wrench
Plier, Needle Nose
Plier, Needle Nose
elenco solder stati
rosen core solder
brass standoffs
nylon/plastic standoffs
Dupont jumpers-Male to Male
Dupont jumpers-Female to Female
Dupont jumpers- Female to Mal

Story

Read more

Schematics

ATMegaZero Arduino wiring

BlockDiagram-Interconnect

ATMegaZero pin-out

This is pin-out

Raspberry Pi PICO RP2040 pin-out

Raspberry Pi PICO RP2040 pin-out

Basic L298N or L9110S wiring

Raspberry Pi PICO code wiring

ATMegaZero code wiring

Code

Raspberry Pi PICO RP2040

MicroPython
This is basic DC Motor control for dual L298N or L9110S motor controllers
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# This example uses an L9110 H-bridge driver to run a DC Motor using two PWM pins.
#  https://www.adafruit.com/product/4489

# Hardware setup:
#   DC motor via L9110 H-bridge driver on two PWM pins that are on their own channels
#   e.g., RP2040 Pico pins GP28, GP27

import time
import board
import pwmio
from adafruit_motor import motor

PWM_PIN_A = board.GP28  # pick any pwm pins on their own channels
PWM_PIN_B = board.GP27
PWM_PIN_C = board.GP26  # pick any pwm pins on their own channels
PWM_PIN_D = board.GP22
PWM_PIN_E = board.GP21  # pick any pwm pins on their own channels
PWM_PIN_F = board.GP20
PWM_PIN_G = board.GP19  # pick any pwm pins on their own channels
PWM_PIN_H = board.GP18


# DC motor setup
# DC Motors generate electrical noise when running that can reset the microcontroller in extreme
# cases. A capacitor can be used to help prevent this.
pwm_a = pwmio.PWMOut(PWM_PIN_A, frequency=50)
pwm_b = pwmio.PWMOut(PWM_PIN_B, frequency=50)
motor1 = motor.DCMotor(pwm_a, pwm_b)
pwm_c = pwmio.PWMOut(PWM_PIN_C, frequency=50)
pwm_d = pwmio.PWMOut(PWM_PIN_D, frequency=50)
motor2 = motor.DCMotor(pwm_c, pwm_d)
pwm_e = pwmio.PWMOut(PWM_PIN_E, frequency=50)
pwm_f = pwmio.PWMOut(PWM_PIN_F, frequency=50)
motor3 = motor.DCMotor(pwm_e, pwm_f)
pwm_g = pwmio.PWMOut(PWM_PIN_G, frequency=50)
pwm_h = pwmio.PWMOut(PWM_PIN_H, frequency=50)
motor4 = motor.DCMotor(pwm_g, pwm_h)

print("***DC motor test***")

print("\nForwards slow")
motor1.throttle = 0.5
motor2.throttle = 0.5
motor3.throttle = 0.5
motor4.throttle = 0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nForwards")
motor1.throttle = 1.0
motor2.throttle = 1.0
motor3.throttle = 1.0
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nBackwards")
motor1.throttle = -1.0
motor2.throttle = -1.0
motor3.throttle = -1.0
motor4.throttle = -1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nBackwards slow")
motor1.throttle = -0.5
motor2.throttle = -0.5
motor3.throttle = -0.5
motor4.throttle = -0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nTurn left")
motor1.throttle = -0.5
motor2.throttle = 1.0
motor3.throttle = -0.5
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nTurn Right")
motor1.throttle = 1.0
motor2.throttle = -0.5
motor3.throttle = 1.0
motor4.throttle = -0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nPivot left")
motor1.throttle = -1.0
motor2.throttle = 1.0
motor3.throttle = -1.0
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nPivot Right")
motor1.throttle = 1.0
motor2.throttle = -1.0
motor3.throttle = 1.0
motor4.throttle = -1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nSpin freely")
motor1.throttle = None
motor2.throttle = None
motor3.throttle = None
motor4.throttle = None
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)

print("\n***Motor test is complete***")

ATMegazero-32 code.py

MicroPython
This is the basic DC motor code for dual L298N or L9110S motor controllers
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# This example uses an L9110 H-bridge driver to run a DC Motor using two PWM pins.
#  https://www.adafruit.com/product/4489

# Hardware setup:
#   DC motor via L9110 H-bridge driver on two PWM pins that are on their own channels
#   e.g., RP2040 Pico pins GP28, GP27

import time
import board
import pwmio
from adafruit_motor import motor

PWM_PIN_A = board.D4  # pick any pwm pins on their own channels
PWM_PIN_B = board.D5
PWM_PIN_C = board.D8  # pick any pwm pins on their own channels
PWM_PIN_D = board.D7
PWM_PIN_E = board.D6  # pick any pwm pins on their own channels
PWM_PIN_F = board.D9
PWM_PIN_G = board.D10  # pick any pwm pins on their own channels
PWM_PIN_H = board.D13

# DC motor setup
# DC Motors generate electrical noise when running that can reset the microcontroller in extreme
# cases. A capacitor can be used to help prevent this.
pwm_a = pwmio.PWMOut(PWM_PIN_A, frequency=50)
pwm_b = pwmio.PWMOut(PWM_PIN_B, frequency=50)
motor1 = motor.DCMotor(pwm_a, pwm_b)
pwm_c = pwmio.PWMOut(PWM_PIN_C, frequency=50)
pwm_d = pwmio.PWMOut(PWM_PIN_D, frequency=50)
motor2 = motor.DCMotor(pwm_c, pwm_d)
pwm_e = pwmio.PWMOut(PWM_PIN_E, frequency=50)
pwm_f = pwmio.PWMOut(PWM_PIN_F, frequency=50)
motor3 = motor.DCMotor(pwm_e, pwm_f)
pwm_g = pwmio.PWMOut(PWM_PIN_G, frequency=50)
pwm_h = pwmio.PWMOut(PWM_PIN_H, frequency=50)
motor4 = motor.DCMotor(pwm_g, pwm_h)

print("***DC motor test***")

print("\nForwards slow")
motor1.throttle = 0.5
motor2.throttle = 0.5
motor3.throttle = 0.5
motor4.throttle = 0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nForwards")
motor1.throttle = 1.0
motor2.throttle = 1.0
motor3.throttle = 1.0
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nBackwards")
motor1.throttle = -1.0
motor2.throttle = -1.0
motor3.throttle = -1.0
motor4.throttle = -1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nBackwards slow")
motor1.throttle = -0.5
motor2.throttle = -0.5
motor3.throttle = -0.5
motor4.throttle = -0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nTurn left")
motor1.throttle = -0.5
motor2.throttle = 1.0
motor3.throttle = -0.5
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nTurn Right")
motor1.throttle = 1.0
motor2.throttle = -0.5
motor3.throttle = 1.0
motor4.throttle = -0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nPivot left")
motor1.throttle = -1.0
motor2.throttle = 1.0
motor3.throttle = -1.0
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nPivot Right")
motor1.throttle = 1.0
motor2.throttle = -1.0
motor3.throttle = 1.0
motor4.throttle = -1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nSpin freely")
motor1.throttle = None
motor2.throttle = None
motor3.throttle = None
motor4.throttle = None
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)

print("\n***Motor test is complete***")

ATMegaZero-WIFI usage code

Arduino
If use of ESP8266-ESP01S module use this code and rewire accordingly
const int AIA = 7;
const int AIB = 6;
const int BIA = 10;
const int BIB = A1;
const int AIA2 = 12;
const int AIB2 = A5;
const int BIA2 = A4;
const int BIB2 = A3;

byte speed = 255;

void setup() {
 pinMode(AIA, OUTPUT);
 pinMode(AIB, OUTPUT);
 pinMode(BIA, OUTPUT);
 pinMode(BIB, OUTPUT);
 pinMode(AIA2, OUTPUT);
 pinMode(AIB2, OUTPUT);
 pinMode(BIA2, OUTPUT);
 pinMode(BIB2, OUTPUT);
}
void loop() {
 stop();
 delay(5000);
 forward();
 delay(2000);
 backward();
 delay(2000);
 left();
 delay(2000);
 right();
 delay(2000);
 stop();
 delay(5000);
}
void backward()
{
 analogWrite(AIA, 0);
 analogWrite(AIB, speed);
 analogWrite(BIA, 0);
 analogWrite(BIB, speed);
 analogWrite(AIA2, 0);
 analogWrite(AIB2, speed);
 analogWrite(BIA2, 0);
 analogWrite(BIB2, speed);
}
void forward()
{
 analogWrite(AIA, speed);
 analogWrite(AIB, 0);
 analogWrite(BIA, speed);
 analogWrite(BIB, 0);
 analogWrite(AIA2, speed);
 analogWrite(AIB2, 0);
 analogWrite(BIA2, speed);
 analogWrite(BIB2, 0);
}
void left()
{
 analogWrite(AIA, speed);
 analogWrite(AIB, 0);
 analogWrite(BIA, 0);
 analogWrite(BIB, speed);
 analogWrite(AIA2, speed);
 analogWrite(AIB2, 0);
 analogWrite(BIA2, 0);
 analogWrite(BIB2, speed);
}
void right()
{
 analogWrite(AIA, 0);
 analogWrite(AIB, speed);
 analogWrite(BIA, speed);
 analogWrite(BIB, 0);
 analogWrite(AIA2, 0);
 analogWrite(AIB2, speed);
 analogWrite(BIA2, speed);
 analogWrite(BIB2, 0);
}
void stop()
{
 analogWrite(AIA, 0);
 analogWrite(AIB, 0);
 analogWrite(BIA, 0);
 analogWrite(BIB, 0);
 analogWrite(AIA2, 0);
 analogWrite(AIB2, 0);
 analogWrite(BIA2, 0);
 analogWrite(BIB2, 0);
}

ATMegaZero32 -WIFI usage- code.py

MicroPython
This code revision incorporates pin changes due to ESP8266-ESP01S usage
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# This example uses an L9110 H-bridge driver to run a DC Motor using two PWM pins.
#  https://www.adafruit.com/product/4489

# Hardware setup:
#   DC motor via L9110 H-bridge driver on two PWM pins that are on their own channels
#   e.g., RP2040 Pico pins GP28, GP27

import time
import board
import pwmio
from adafruit_motor import motor

PWM_PIN_A = board.D7  # PIN 16 (D4) pick any pwm pins on their own channels
PWM_PIN_B = board.D6  # PIN 18 (D5)
PWM_PIN_C = board.D10 # PIN 26 (D8) pick any pwm pins on their own channels
PWM_PIN_D = board.A1  # PIN 37
PWM_PIN_E = board.D12 # PIN 31 pick any pwm pins on their own channels
PWM_PIN_F = board.A5  # PIN 32 (D9)
PWM_PIN_G = board.A4  # PIN 33 pick any pwm pins on their own channels
PWM_PIN_H = board.A3  # PIN 35

# DC motor setup
# DC Motors generate electrical noise when running that can reset the microcontroller in extreme
# cases. A capacitor can be used to help prevent this.
pwm_a = pwmio.PWMOut(PWM_PIN_A, frequency=50)
pwm_b = pwmio.PWMOut(PWM_PIN_B, frequency=50)
motor1 = motor.DCMotor(pwm_a, pwm_b)
pwm_c = pwmio.PWMOut(PWM_PIN_C, frequency=50)
pwm_d = pwmio.PWMOut(PWM_PIN_D, frequency=50)
motor2 = motor.DCMotor(pwm_c, pwm_d)
pwm_e = pwmio.PWMOut(PWM_PIN_E, frequency=50)
pwm_f = pwmio.PWMOut(PWM_PIN_F, frequency=50)
motor3 = motor.DCMotor(pwm_e, pwm_f)
pwm_g = pwmio.PWMOut(PWM_PIN_G, frequency=50)
pwm_h = pwmio.PWMOut(PWM_PIN_H, frequency=50)
motor4 = motor.DCMotor(pwm_g, pwm_h)

print("***DC motor test***")

print("\nForwards slow")
motor1.throttle = 0.5
motor2.throttle = 0.5
motor3.throttle = 0.5
motor4.throttle = 0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nForwards")
motor1.throttle = 1.0
motor2.throttle = 1.0
motor3.throttle = 1.0
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nBackwards")
motor1.throttle = -1.0
motor2.throttle = -1.0
motor3.throttle = -1.0
motor4.throttle = -1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nBackwards slow")
motor1.throttle = -0.5
motor2.throttle = -0.5
motor3.throttle = -0.5
motor4.throttle = -0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nTurn left")
motor1.throttle = -0.5
motor2.throttle = 1.0
motor3.throttle = -0.5
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nTurn Right")
motor1.throttle = 1.0
motor2.throttle = -0.5
motor3.throttle = 1.0
motor4.throttle = -0.5
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nPivot left")
motor1.throttle = -1.0
motor2.throttle = 1.0
motor3.throttle = -1.0
motor4.throttle = 1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nPivot Right")
motor1.throttle = 1.0
motor2.throttle = -1.0
motor3.throttle = 1.0
motor4.throttle = -1.0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nStop")
motor1.throttle = 0
motor2.throttle = 0
motor3.throttle = 0
motor4.throttle = 0
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)
time.sleep(1)

print("\nSpin freely")
motor1.throttle = None
motor2.throttle = None
motor3.throttle = None
motor4.throttle = None
print("  throttle:", motor1.throttle)
print("  throttle:", motor2.throttle)
print("  throttle:", motor3.throttle)
print("  throttle:", motor4.throttle)

print("\n***Motor test is complete***")

ATMegaZero Arduino code

Arduino
This is basic DC Motor code for dual L298N or L9110S motor controllers
/*  ___   ___  ___  _   _  ___   ___   ____ ___  ____  
 * / _ \ /___)/ _ \| | | |/ _ \ / _ \ / ___) _ \|    \ 
 *| |_| |___ | |_| | |_| | |_| | |_| ( (__| |_| | | | |
 * \___/(___/ \___/ \__  |\___/ \___(_)____)___/|_|_|_|
 *                  (____/ 
 * Arduino Mecanum Omni Direction Wheel Robot Car
 * Tutorial URL http://osoyoo.com/?p=30022
 * CopyRight www.osoyoo.com

 * After running the code, smart car will 
 * go forward and go backward for 2 seconds, 
 * left turn and right turn for 2 seconds, 
 * right shift and left shift for 2 seconds,
 * left diagonal back and right diagonal forward for 2 seconds,
 * left diagonal forward and right diagonal back for 2 seconds,
 * then stop. 
 * 
 */
 /*
 * Modified by James Martel for use with ATMegaZero
 * and two L298N Modules
 */
#define Speed 200  //140
#define SPEED 200  //140 
#define TURN_SPEED 160    
#define speedPinR 6   //18 Front Wheel PWM pin connect Right MODEL-X ENA 
#define RightMotorDirPin1 4    //11 32 Front Right Motor direction pin 1 to Right MODEL-X IN1  (K1)
#define RightMotorDirPin2 8   //13 36 Front Right Motor direction pin 2 to Right MODEL-X IN2   (K1)                                 
#define LeftMotorDirPin1 12    //31 A5 38 Front Left Motor direction pin 1 to Right MODEL-X IN3 (K3)
#define LeftMotorDirPin2 18   //33 A2 40 Front Left Motor direction pin 2 to Right MODEL-X IN4 (K3)
#define speedPinL 5   //12 16 Front Wheel PWM pin connect Right MODEL-X ENB

#define speedPinRB 9   //22 15 Rear Wheel PWM pin connect Left MODEL-X ENA 
#define RightMotorDirPin1B 17    //35 29 Rear Right Motor direction pin 1 to Left  MODEL-X IN1 ( K1)
#define RightMotorDirPin2B 15    //37 31 Rear Right Motor direction pin 2 to Left  MODEL-X IN2 ( K1) 
#define LeftMotorDirPin1B 16    //36 A4 33 Rear Left Motor direction pin 1 to Left  MODEL-X IN3  (K3)
#define LeftMotorDirPin2B 14  //38 A3 35 Rear Left Motor direction pin 2 to Left  MODEL-X IN4 (K3)
#define speedPinLB 10    //26 13 Rear Wheel PWM pin connect Left MODEL-X ENB

/*motor control*/
void go_advance(int speed){
   RL_fwd(speed);
   RR_fwd(speed);
   FR_fwd(speed);
   FL_fwd(speed); 
}
void go_back(int speed){
   RL_bck(speed);
   RR_bck(speed);
   FR_bck(speed);
   FL_bck(speed); 
}
void right_shift(int speed_fl_fwd,int speed_rl_bck ,int speed_rr_fwd,int speed_fr_bck) {
  FL_fwd(speed_fl_fwd); 
  RL_bck(speed_rl_bck); 
  RR_fwd(speed_rr_fwd);
  FR_bck(speed_fr_bck);
}
void left_shift(int speed_fl_bck,int speed_rl_fwd ,int speed_rr_bck,int speed_fr_fwd){
   FL_bck(speed_fl_bck);
   RL_fwd(speed_rl_fwd);
   RR_bck(speed_rr_bck);
   FR_fwd(speed_fr_fwd);
}

void left_turn(int speed){
   RL_bck(0);
   RR_fwd(speed);
   FR_fwd(speed);
   FL_bck(0); 
}
void right_turn(int speed){
   RL_fwd(speed);
   RR_bck(0);
   FR_bck(0);
   FL_fwd(speed); 
}
void left_back(int speed){
   RL_fwd(0);
   RR_bck(speed);
   FR_bck(speed);
   FL_fwd(0); 
}
void right_back(int speed){
   RL_bck(speed);
   RR_fwd(0);
   FR_fwd(0);
   FL_bck(speed); 
}
void clockwise(int speed){
   RL_fwd(speed);
   RR_bck(speed);
   FR_bck(speed);
   FL_fwd(speed); 
}
void countclockwise(int speed){
   RL_bck(speed);
   RR_fwd(speed);
   FR_fwd(speed);
   FL_bck(speed); 
}


void FR_fwd(int speed)  //front-right wheel forward turn
{
  digitalWrite(RightMotorDirPin1,HIGH);
  digitalWrite(RightMotorDirPin2,LOW); 
  analogWrite(speedPinR,speed);
}
void FR_bck(int speed) // front-right wheel backward turn
{
  digitalWrite(RightMotorDirPin1,LOW);
  digitalWrite(RightMotorDirPin2,HIGH); 
  analogWrite(speedPinR,speed);
}
void FL_fwd(int speed) // front-left wheel forward turn
{
  digitalWrite(LeftMotorDirPin1,HIGH);
  digitalWrite(LeftMotorDirPin2,LOW);
  analogWrite(speedPinL,speed);
}
void FL_bck(int speed) // front-left wheel backward turn
{
  digitalWrite(LeftMotorDirPin1,LOW);
  digitalWrite(LeftMotorDirPin2,HIGH);
  analogWrite(speedPinL,speed);
}

void RR_fwd(int speed)  //rear-right wheel forward turn
{
  digitalWrite(RightMotorDirPin1B,HIGH);
  digitalWrite(RightMotorDirPin2B,LOW); 
  analogWrite(speedPinRB,speed);
}
void RR_bck(int speed)  //rear-right wheel backward turn
{
  digitalWrite(RightMotorDirPin1B,LOW);
  digitalWrite(RightMotorDirPin2B,HIGH); 
  analogWrite(speedPinRB,speed);
}
void RL_fwd(int speed)  //rear-left wheel forward turn
{
  digitalWrite(LeftMotorDirPin1B,HIGH);
  digitalWrite(LeftMotorDirPin2B,LOW);
  analogWrite(speedPinLB,speed);
}
void RL_bck(int speed)    //rear-left wheel backward turn
{
  digitalWrite(LeftMotorDirPin1B,LOW);
  digitalWrite(LeftMotorDirPin2B,HIGH);
  analogWrite(speedPinLB,speed);
}
 
void stop_Stop()    //Stop
{
  analogWrite(speedPinLB,0);
  analogWrite(speedPinRB,0);
  analogWrite(speedPinL,0);
  analogWrite(speedPinR,0);
}


//Pins initialize
void init_GPIO()
{
  pinMode(RightMotorDirPin1, OUTPUT); 
  pinMode(RightMotorDirPin2, OUTPUT); 
  pinMode(speedPinL, OUTPUT);  
 
  pinMode(LeftMotorDirPin1, OUTPUT);
  pinMode(LeftMotorDirPin2, OUTPUT); 
  pinMode(speedPinR, OUTPUT);
  
  pinMode(RightMotorDirPin1B, OUTPUT); 
  pinMode(RightMotorDirPin2B, OUTPUT); 
  pinMode(speedPinLB, OUTPUT);  
 
  pinMode(LeftMotorDirPin1B, OUTPUT);
  pinMode(LeftMotorDirPin2B, OUTPUT); 
  pinMode(speedPinRB, OUTPUT);
   
  stop_Stop();
}

void setup()
{
init_GPIO();
 
go_advance(SPEED);
     delay(5000);
     stop_Stop();
     delay(1000);
  
go_back(SPEED);
     delay(5000);
     stop_Stop();
     delay(1000);
	  
left_turn(TURN_SPEED);
     delay(5000);
     stop_Stop();
     delay(1000);
	  
right_turn(TURN_SPEED);
     delay(5000);
     stop_Stop();
     delay(1000);
  
right_shift(200,200,200,200); //right shift
     delay(5000);
     stop_Stop();
     delay(1000);

left_shift(200,200,200,200); //left shift
     delay(5000);
     stop_Stop();
     delay(1000);
	 
left_shift(200,0,200,0); //left diagonal back
     delay(5000);
     stop_Stop();
	   delay(1000);
 
right_shift(200,0,200,0); //right diagonal ahead
     delay(5000);
     stop_Stop();
	   delay(1000);

left_shift(0,200,0,200); //left diagonal ahead
     delay(5000);
     stop_Stop();
     delay(1000);

right_shift(0,200,0,200); //right diagonal back
     delay(5000);
     stop_Stop();
	   delay(1000);
}

void loop()
{
  
}

ATMegaZero Arduino code less PWM

Arduino
This is final basic DC Motor code without PWM for L298N or L9110S motor controllers
const int AIA = 8;
const int AIB = 4;
const int BIA = 6;
const int BIB = 7;
const int AIA2 = 12;
const int AIB2 = 13;
const int BIA2 = 9;
const int BIB2 = A5;

byte speed = 255;

void setup() {
 pinMode(AIA, OUTPUT);
 pinMode(AIB, OUTPUT);
 pinMode(BIA, OUTPUT);
 pinMode(BIB, OUTPUT);
 pinMode(AIA2, OUTPUT);
 pinMode(AIB2, OUTPUT);
 pinMode(BIA2, OUTPUT);
 pinMode(BIB2, OUTPUT);
}
void loop() {
 forward();
 delay(2000);
 backward();
 delay(2000);
 left();
 delay(2000);
 right();
 delay(2000);
 stop();
 delay(5000);
}
void backward()
{
 analogWrite(AIA, 0);
 analogWrite(AIB, speed);
 analogWrite(BIA, 0);
 analogWrite(BIB, speed);
 analogWrite(AIA2, 0);
 analogWrite(AIB2, speed);
 analogWrite(BIA2, 0);
 analogWrite(BIB2, speed);
}
void forward()
{
 analogWrite(AIA, speed);
 analogWrite(AIB, 0);
 analogWrite(BIA, speed);
 analogWrite(BIB, 0);
 analogWrite(AIA2, speed);
 analogWrite(AIB2, 0);
 analogWrite(BIA2, speed);
 analogWrite(BIB2, 0);
}
void left()
{
 analogWrite(AIA, speed);
 analogWrite(AIB, 0);
 analogWrite(BIA, 0);
 analogWrite(BIB, speed);
 analogWrite(AIA2, speed);
 analogWrite(AIB2, 0);
 analogWrite(BIA2, 0);
 analogWrite(BIB2, speed);
}
void right()
{
 analogWrite(AIA, 0);
 analogWrite(AIB, speed);
 analogWrite(BIA, speed);
 analogWrite(BIB, 0);
 analogWrite(AIA2, 0);
 analogWrite(AIB2, speed);
 analogWrite(BIA2, speed);
 analogWrite(BIB2, 0);
}
void stop()
{
 analogWrite(AIA, 0);
 analogWrite(AIB, 0);
 analogWrite(BIA, 0);
 analogWrite(BIB, 0);
 analogWrite(AIA2, 0);
 analogWrite(AIB2, 0);
 analogWrite(BIA2, 0);
 analogWrite(BIB2, 0);
}

Credits

James Martel

James Martel

48 projects β€’ 61 followers
Self taught Robotics platform developer with electronics background

Comments