Tag Archives: RaspberryPi

Change i2c address of ina219

Hi everyone,

I wanted to use ina219 with pca9685 but they shared the same i2c address 0x4:

Luckily, there’s a fairly easy fix for this. All we need to do is solder two pins together. We’re going to bridge a0 and this will change our address to 0x41.

In order to check these run sudo i2cdetect -y 1 pm the raspberry pi:

After soldering it becomes:

You can solder a combination of pins for different addresses:
None = 0x40 (default)
A0 = 0x41
A1 = 0x44 (the one I’ve soldered to get 44)
A0 + A1 = 0x45

A4988 Stepper motor RaspberryPi

We’re using a 42shd0034-20B Geetech stepping motor taken from a 3d printer:

We’ll be driving it with an A4988 stepper motor controller. You can pick up five packs of these for less than $2 online – definitely worth having a few extras around:

The datasheet is available here: https://www.pololu.com/file/download/A4988.pdf?file_id=0J450

The following diagram illustrates what we’ll be doing:

Once everything is connected it’ll end up looking something like this:

To start, connect your stepping and direction pins. I’ve used GPIO16 for stepping and GPIO21 for direction:

Each time GPIO16 is set to HIGH it will make the stepper motor take one step. When the direction pin is HIGH the stepper motor will go clockwise, when it’s LOW, anti-clockwise.

If you’re not using the sleep functionality, connect the RESET and SLP pins together and then wire them directly to 3.3v:

Using a separate power source wire 12v to the GND and VMOT pins. You should also place a capacitor across these pins as close to the board as possible. Generally the longest leg is positive. You’ll also need to connect the external GND to the Raspberry Pi’s GND:

Connect the four pins of the stepper motor:

Connect the A4988 to 3.3v and common GND:

The code is pretty straight forward but I’ve provided a class below to help you get started:

# System imports
import RPi.GPIO as GPIO
from time import sleep

class StepperHandler():


def __init__(self, stepPin, directionPin, delay=0.208, stepsPerRevolution=200):

# Configure instance
self.StepPin = stepPin
self.DirectionPin = directionPin
self.Delay = delay
self.RevolutionSteps = stepsPerRevolution
self.CurrentDirection = self.CLOCKWISE
self.CurrentStep = 0

# Setup gpio pins
GPIO.setup(self.StepPin, GPIO.OUT)
GPIO.setup(self.DirectionPin, GPIO.OUT)

def Step(self, stepsToTake, direction = __CLOCKWISE):

print("Step Pin: " + str(self.StepPin) + " Direction Pin: " + str(self.DirectionPin) + " Delay: " + str(self.Delay))
print("Taking " + str(stepsToTake) + " steps.")

# Set the direction
GPIO.output(self.DirectionPin, direction)

# Take requested number of steps
for x in range(stepsToTake):
print("Step " + str(x))
GPIO.output(self.StepPin, GPIO.HIGH)
self.CurrentStep += 1
GPIO.output(self.StepPin, GPIO.LOW)

# Define pins

# Create a new instance of our stepper class (note if you're just starting out with this you're probably better off using a delay of ~0.1)
stepperHandler = StepperHandler(STEP_PIN, DIRECTION_PIN, 0.0025)

# Go forwards once

# Go backwards once
stepperHandler.Step(200, stepperHandler.ANTI_CLOCKWISE)

Update Wireless Info on Raspberry Pi

Hi everyone,

Just a quick post on how to configure wireless info on a raspberry pi. To start with, open the config file:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

You can then add any number of connections to the file with varying priorities:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

        ssid="Mobile Network"

        ssid="Home Network"

Then save the file. Your raspberry pi will now connect to the network with the highest priority first (home network), when that’s not available it will use the network with the lower priority (mobile network).

The official doco is actually pretty good for this use case if you need more info: https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

Using INA219 (GY-219) with the Raspberry Pi

Hi everyone,

I’ve just setup an INA219B Voltage/Current sensor on my RaspberryPi. Just thought I’d link the tutorials and libraries I used – there’s a lot of really useful info out there.

Install the following library via git: https://github.com/chrisb2/pi_ina219
sudo pip3 install pi-ina219

Follow this tutorial: https://www.rototron.info/raspberry-pi-ina219-tutorial/

Misc Notes

  • Common ground is required
  • Vin – and Vin+ are attached to +, neither goes to ground

Custom Sensor Address
na = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS, address=0x41)

Can be configured via the following:

Enable Low Power Between Reads
while True:
print "Voltage : %.3f V" % ina.voltage()

If you’re getting the following error:

OSError: [Errno 121] Remote I/O error

Run the following command:

i2cdetect -y 1

And check to ensure that your device is showing up on 40. If it’s a different number you’ll just need to update the address in your code e.g. (0x40, 0x41, etc.)

Mini-360 DC-DC Buck Converter – Incorrect Voltage 10v Instead of 5v

Hi everyone,

I’ve been playing around with a few DC-DC buck converters similar to these ones: https://www.amazon.com.au/UEB-Power-Converter-Module-Supply/dp/B078CXHWXC/ref=sr_1_fkmr1_1?ie=UTF8&qid=1519030369&sr=8-1-fkmr1&keywords=mini+360+buck+converter

I had expected 5v output from my 12v supply but when I hooked it up to a multimeter I found I was getting just over 10v. This would fry pretty much everything in my circuit so I was pretty worried.

After a bit of research, I came across a thread on eevblog that mentioned a screw for adjustment. Looking closely you can see that there is a small screw on the side of the chip. Turning this quarter of a rotation anti-clockwise put mine at exactly 5.04 volts.

A few other small tips:

  • The thread seems to indicate that some models require a lot more turning (up to 30 seconds for one poster).
  • I had to push down fairly hard to get it to actually turn the part underneath instead of just the metal cover

Hopefully this helps someone else out!

Eevblog: https://www.eevblog.com/forum/beginners/dc-dc-buck-converter-step-down-module-lm2596-power-supply/


Duinotech Hall Effect Sensor with RaspberryPi

Hi everyone,

This is just a quick post to cover how the Duinotech hall effect sensor module (XC-4434) can be hooked up to a RaspberryPi.

Sample Code

The code below will output a zero when the sensor is activated by a magnet, otherwise a zero.

import time
import datetime
import RPi.GPIO as GPIO

# Define constants

# Setup GPIO pins
GPIO.setup(BUCKET_HALL_EFFECT_SIG_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Important

while True:



When near a magnetic field the light on the sensor will turn on. If you’re using the sample code above, a zero will be shown when close to a magnet, otherwise a 1.


Purchased from: https://www.jaycar.com.au/arduino-compatible-hall-effect-sensor-module/p/XC4434

Spec Sheet: Z7275

AttributeError: module ‘serial’ has no attribute ‘SerialException’ – Python 3.5

Hi everyone,

A quick fix for an error I ran into while updating to Pyhton 3.5.2:

AttributeError: module 'serial' has no attribute 'SerialException'

I needed to add pyserial:

pi@raspberrypi:~/Desktop/piscripts/get-commands $ sudo pip3.5 install pyserial
Collecting pyserial
  Downloading pyserial-3.4-py2.py3-none-any.whl (193kB)
    100% |████████████████████████████████| 194kB 530kB/s
Installing collected packages: pyserial
Successfully installed pyserial-3.4

Thanks to the following link: https://stackoverflow.com/a/47562659/522859