Makerverse 2ch Motor driver with Piicodev BME280

Have used Piicodev BME280 library and Makerverse motor library successfully separately, but if I initialise an instance of BME280 sensor I have problems. Sometimes a reboot “hangs” but if it succeeds then one motor channel is on constantly. I assume it has something to do with the GPIO pins I am using (2,3,4,5).
Is there a way of changing the default I2C pins for Piicodev?

1 Like

Hi John,

Interesting issue, would it be possible to send through a copy of your code and a photo.

You can certainly can change the I2C pins: GitHub - CoreElectronics/CE-PiicoDev-BME280-MicroPython-Module: This is the firmware repo for the Core Electronics PiicoDev® Atmospheric Sensor BME280

For example, if you wanted to use pins 20 and 21 (Uses I2C1, not 0 which is default), and making sure to import Pin!

from machine import Pin
atmo = PiicoDev_BME280(bus=1, sda=Pin(20),scl=Pin(21))

Liam

1 Like

Hi Liam,

the relevant code is listed below…

import uasyncio
from microdot_asyncio import Microdot, Response
from microdot_utemplate import render_template

from Makerverse_Motor_2ch import twoMotorRobot

from myhtml import menuhtml
from machine import Pin
from time import sleep

import random

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function

dir_A = Pin(2, Pin.OUT)
dir_A.value(0)
dir_B = Pin(4, Pin.OUT)
dir_B.value(0)
pwm_A = Pin(3, Pin.OUT)
pwm_A.value(0)
pwm_B = Pin(5, Pin.OUT)
pwm_B.value(0)

johnny5 = twoMotorRobot(pwmPinLeft = 3, dirPinLeft = 2,
pwmPinRight = 5, dirPinRight = 4)

try:
sensor = PiicoDev_BME280() # initialise the sensor
except:
print('No BME280 detected.’)

If I comment out the code in BLUE it all works fine.

Will try initialising with the code you supplied and get back to you.

Cheers

2 Likes

Hi John,

Sorry the PiicoDev Expansion board only breaks the I2C pins out via 8/9 so you’d have to wire them out of the respective pins directly.

If you strip back your code to run just the sensor and motor driver does that work? There might be some conflicts with scheduling somewhere

1 Like

On this particular project, I am not using the Piicodev breakout just the BME280 so it should work with what you gave me. Won’t get to it until tomorrow to test.

2 Likes

I tried instantiating the BME280 sensor with different SCL and SDA pin designations and all works well.
Thank you for finding a simple solution.

Cheers

3 Likes

Glad to hear John!

Thanks for circling back and posting that it worked!
We’re keen to see what you make😁

2 Likes