I2C interface

Description of I2C interface

Raspberry Pi SPI and I2C Tutorial

Continuous deployment (Russian) Непрерывная кросс компиляция на Raspberry PI

Controlling motors

Brushless motor

Control brushless motor with ESC. Without additional controllers

With PCA9685 PWM Board (stackexchange thread)

One more thread

Controlling multiple servos

To control multiple servos you can use PCA9685 controller. Connection is shown below. It’s better to connect VCC of the controller (red wire) to +5V or raspberry or to external power supply.

You have to enable I2C interface first with `sudo raspi-config`. Choose "Interfacing Options" -> "I2C" -> "Enable".

Now installing the diagnostic tool and running:

sudo apt-get install -y i2c-tools
sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         

Now we can install library:

pip install Adafruit_PCA9685

and run a simple program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# sample.py
# Simple demo of of the PCA9685 PWM servo/LED controller library.
# This will move channel 0 from min to max position repeatedly.
# Author: Tony DiCola
# License: Public Domain
from __future__ import division
import time

# Import the PCA9685 module.
import Adafruit_PCA9685


# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)

# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()

# Alternatively specify a different address and/or bus:
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)

# Configure min and max servo pulse lengths
servo_min = 150  # Min pulse length out of 4096
servo_max = 600  # Max pulse length out of 4096

# Helper function to make setting a servo pulse width simpler.
def set_servo_pulse(channel, pulse):
    pulse_length = 1000000    # 1,000,000 us per second
    pulse_length //= 60       # 60 Hz
    print('{0}us per period'.format(pulse_length))
    pulse_length //= 4096     # 12 bits of resolution
    print('{0}us per bit'.format(pulse_length))
    pulse *= 1000
    pulse //= pulse_length
    pwm.set_pwm(channel, 0, pulse)

# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)

print('Moving servo on channel 0, press Ctrl-C to quit...')
while True:
    # Move servo on channel O between extremes.
    pwm.set_pwm(0, 0, servo_min)
    time.sleep(1)
    pwm.set_pwm(0, 0, servo_max)
time.sleep(1)

running:

python sample.py

To control more than 16 servose one can chain multiple drivers. See Chaining Drivers section for details. Some soldering is required to assign a unique address for each driver.

See alow:

Stepper motors / DC (brushed) motors

with l293d

[Raspberry] Stepper and dc motor using specializer HAT
Based on PC9865 PWM and TB6612 chipset. 1.2A per channel current capability (20ms long bursts of 3A peak)

[Arduino] With adafruit motor schield v1
Based on 74HC595N Serial to parallel output latch and L293D driver. 0.6A per bridge (1.2A peak) with thermal shutdown protection, 4.5V to 25V.
Library for motor control
See also about SN74HC595 shift register

[Arduino] With adafruit motor shield v2
Based on PCA9685 and TB6612 MOSFET drivers with 1.2A per channel current capability ( up to 3A peak for approx 20ms at a time)

[Raspberry] Drive a DC motor forward and in reverse with variable speed (with l293d, adafruit lesson 9)

[Micropython board] Control dc motor with pca9685

[Raspberry] Video with just simple transistor scheme and with L293D controller

[Raspberry] using L293D and 4N35 opto isolator

[Arduino] 1 bidirectional DC motor using small DRV8871 motor driver
Up to 45V and 3.6A of motor control

It is possible to have frequency controlled dc driver connected through Adafruit 16 Channel Servo Driver. See post. controller, ~100 Euro, powerfull

[Arduino] using drv8833 driver,

[Arduino] using l293d

Using transistors: (1)[http://electronics.stackexchange.com/questions/7235/motor-driver-using-only-a-2n2222-transistor], very weak

Connecting via ssh:

ssh -Y user@raspberrypi-url

Access rasbberry Pi without monitor and ethernet

Assuming we have an operating system (raspbian) installed.

  1. Plug the SD-card into a computer.

  2. Automatic connection to wifi. Edit /etc/wpa_supplicant/wpa_supplicant.conf and add the following lines:

network={
    ssid="my-network-name"
    psk="my-network-pass"
}

In the end the file should look like this:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="my-network-name"
    psk="my-network-pass"
}

country field is essential. Wifi wont work without it. In the log you will see raspberrypi systemd[1]: Started Disable WiFi if country not set.

If you need to support multiple wifi connections use id_str field:

network={
    ssid="my-network-name"
    psk="my-network-pass"
    id_str="net1"
}

network={
    ssid="another-network"
    psk="another pass"
    id_str="net2"
}

  1. Enable SSH access. Create an empty file ssh in /boot/.

  2. Plug the card back into your raspberry, turn on.

Now you can connect to raspberry via ssh:

ssh pi@raspberrypi

or

ssh pi@<IP-OF-YOUR-RASPBERRY>

Reading input (button) from GPIO

without interrupts, raspi.tv

RaspberryPi Zero pins Layout

GPIO raspberry pins scheme

pins layout photo image source

Interactive website for pinout of Raspberry Pi for different interfaces Pinout

Donkey car

Requirements for running donkey car:

sudo apt install -y libatlas-base-dev libopenjp2-7-dev libtiff5-dev libhdf5-dev

Other