Skip to main content

I2C Motor Controller for Raspberry Pi/Arduino robots

Project description

ZenBot-Pi

PyPI version Python 3.10 License: MIT

A Python package for controlling Arduino-based motor robots over I2C communication from a Raspberry Pi or other Linux SBCs.

Start Generation Here

Watch the video

End Generation Here

Features

  • Simple control of DC motors connected to an Arduino
  • I2C communication protocol for reliability
  • Command-line interface for manual control
  • Library for integration into your Python projects

Installation

From PyPI```bash

pip install zenbot-pi


### From Source

```bash
git clone https://github.com/yourusername/zenbot-pi.git
cd zenbot-pi
pip install -e .

Hardware Setup

  1. Connect your Raspberry Pi/Orange Pi to Arduino via I2C:
    • Pi SDA → Arduino A4 (SDA)
    • Pi SCL → Arduino A5 (SCL)
    • Pi GND → Arduino GND

Start Generation Here

Pinout Information

  • Motor Control Pins:

    • enA (Pin 6): Enables motor A.
    • in1 (Pin 4): Controls the direction of motor A (input 1).
    • in2 (Pin 5): Controls the direction of motor A (input 2).
    • in3 (Pin 7): Controls the direction of motor B (input 1).
    • in4 (Pin 8): Controls the direction of motor B (input 2).
    • enB (Pin 9): Enables motor B.
  • Buzzer and Button Pins:

    • buzzer (Pin A0): Used to produce sound feedback.
    • startButton (Pin 12): Button to stop the motors for safety.
  • I2C Communication:

    • The Arduino uses the I2C address 0x08 for communication with the Raspberry Pi or other devices.

End Generation Here

  1. Make sure the Arduino is running the provided sketch (see arduino_sketches directory) with I2C slave address set to 0x08.

  2. Enable I2C on your Raspberry Pi:

    sudo raspi-config
    

    Navigate to Interfacing Options → I2C → Enable

    For Orange Pi, use sudo orangepi-config or appropriate method.

Using the CLI

The package provides a command-line interface:

# Run interactive control mode
zenbot-pi interactive

# Run test sequence
zenbot-pi test

# Send direct commands
zenbot-pi direct forward
zenbot-pi direct stop
zenbot-pi direct 5  # Set speed to 5

# Use different I2C bus or address
zenbot-pi --i2c-bus 1 --address 0x09 interactive

Using the Library

Basic usage example:

from zenbot import MotorController

# Create a controller, specifying I2C bus (default: 3) and address (default: 0x08)
controller = MotorController(i2c_bus=3, address=0x08)

# Test communication with Arduino
if controller.test_communication():
    # Set speed (0-9)
    controller.set_speed(5)
    
    # Move the robot
    controller.forward()
    
    # Wait a bit
    import time
    time.sleep(2)
    
    # Stop motors
    controller.stop()
    
    # Clean up when done
    controller.close()

Available Commands

  • forward() - Move robot forward
  • backward() - Move robot backward
  • left() - Turn robot left
  • right() - Turn robot right
  • stop() - Stop all motors
  • set_speed(level) - Set speed level (0-9)
  • get_status() - Get system status
  • send_command(cmd) - Send a raw command character
  • close() - Close I2C connection

Arduino Setup

This library requires an Arduino running the provided sketch. The Arduino sketch:

  1. Listens for commands on I2C bus (address 0x08 by default)
  2. Controls motor driver shield/circuit based on received commands
  3. Provides status feedback

Troubleshooting

  • Check I2C connection with i2cdetect -y [bus_number]
  • Ensure Arduino has the correct I2C address (0x08 by default)
  • Verify power supply is adequate for motors
  • Check log file zenbot.log for debugging information

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zenbot_pi-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zenbot_pi-0.1.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file zenbot_pi-0.1.1.tar.gz.

File metadata

  • Download URL: zenbot_pi-0.1.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for zenbot_pi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1fd8424fd113ab07ec9df2797d09b401694bcdd2e93d6b29900b8b5bd2c09d39
MD5 4542720dd82097233e54443902846095
BLAKE2b-256 752681dc6a9e0d14afef730aa1ce62ebdf352cc4c39309dcc7e5ef260f326a30

See more details on using hashes here.

File details

Details for the file zenbot_pi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: zenbot_pi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for zenbot_pi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f737aa225a9cbdee1552a64a47eb897ebc735a9204ba442d8c5cfebc3ca0bbb
MD5 cc1eadb9c6efe94238ae87b5e67bd69d
BLAKE2b-256 83965181efdbeeed9b930d71ba9c293016a7b6ab9ef3137e77fd879561250a1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page