How to get pHAT Stack to power multiple motor bonnets individually? - raspberry-pi4

We are working with a Raspberry Pi 4B and we are trying to power 6 different stepper motors with it. We have 3 different motor bonnets to drive 2 motors each and we bought the pHAT Stack to connect the 3 motor bonnets to the Raspberry Pi. We need each motor to be controlled individually but right now when we run our script all the motor bonnets do the same thing (i.e. if we control stepper1 on the code, all stepper1s do the same thing).
So our question is, how do we specify the address of each bonnet on the pHAT stack in order to power each motor individually? Or do the motor bonnets all use the same i2c address and the motors are not able to be controlled individually?
Any help would be amazing!
Here is an image of our setup without the power supply and with only 2 motor bonnets and 2 motors (1 in each bonnet as stepper1). For this example setup, how can we configure the address of each bonnet so that we can call it in our code to reference that bonnet when we want to control the motors it’s driving?
The list of parts we are using:
Raspberry Pi 4 B
pHAT Stack
Motor Bonnet
Stepper Motor
We were expecting to be able to stack 3 different bonnets to be able to address each of them with a specific i2c address, but we might not be understanding the way i2c addresses work. We cannot initialize separate motorkits (we are using Adafruit's MotorKit library to drive the stepper motors) with different addresses on the pHAT stack.

Related

Advice needed for connecting multiple arduinos as slave to raspberry pi

I have a project in hand where I need to connect 5 or more arduinos as slaves to Raspberry Pi. Load Cells, Reed Switch, Solenoid lock will be connected to each of the arduino. The arduinos need to send the weight readings when a communication is started by the raspberry pi(master). Only a single arduino will be activated at a time. The arduinos will be placed at a maximum of 6ft distance from the raspberry pi. I need advice regarding how to make this connection. I read that I2C cannot be used for long distances so I am unsure if 6 ft is a long distance for I2C. Next, I am trying to see if a USB would work for my case but the issue is the Pi has only 4 USB slots. So can I use a external USB hub with an external power supply and connected each of the arduinos to the USB hub and provide individual power supply to the arduinos? Will this arrangement work or should I be looking at any other protocol apart from I2C and USB?? Any advice on this will be much appreciated. Thanks a lot for your time.
Arduino (Nano, Uno, Mega etc.) can communicate via SPI, I2C or UART.
Long story short, SPI is not suitable for your application. It is used for fast data transfer over short distances (usually milimeters or centimeters), so mainly for communication between chips mounted on the same PCB or PCBs close together (e.g. display shields).
Using I2C is perfectly fine (let's say up to 10 meters) and in your case it is a way to go. The maximum possible length depends on baud rate, for 10 meters a 9600 baud rate would be OK. The big advantage is that you need only 2 wires to connect all Arduinos, the disadvantage is that only one device can transfer data at the time – in your case, that does not matter.
UART is used for communication with many external modules (GSM, GPS, HMI, ...) and also in combination with USB-TTL chip for communication via USB (virtual COM port). In your case, you can use UART e.g. in combination with external UART-RS485 converter module, but there is no need since you can use I2C.

Problems with pins for interruption and motor DC - Arduino UNO

I am working in a project which requires me to read the velocity of a DC motor with a quadrature encoder. I am using the Arduino UNO board and for some weird reason the motor just works if it is connected to the pins 2 and 3. However this pins are reserved for the interruption (where I intended to connect the encoder). How could I solve this problem?
Assuming the arduino can provide enough current, you should be able to run the motor from any output pin, check out this diagram for reference. You should also make sure you have the necessary protection circuits in place. This is a good starting point: https://create.arduino.cc/projecthub/licensedGeek/controlling-a-dc-motor-from-an-arduino-101-board-f4954b

doit 2-way motor & 16-way servo shield board

Got this board cheap from Banggood, but there are minimal details on how to use it.
There is a manual here https://www.gitbook.com/book/smartarduino/user-manual-for-2-way-motor-16-way-servos-shield/details , but it is a long way from detailed, and what I need are some details on how to drive the I2C PWM servos.
After some poking around, I have a partial answer.
The Adafruit libraries seem to work fine for the servos.
https://learn.adafruit.com/16-channel-pwm-servo-driver/using-the-adafruit-library
Motors on this version of the board have the following controls:
D6 PWMB - speed channel B
D7 DIRB - Direction Channel B
D8 PWMA - Speed Channel A
D9 DIRA - Direction Channel A
... which may explain why the speed control is working on channel B but not A, since pin 8 is not PWM on a UNO. (May also explain why it is cheap)
Also note that you need to supply a separate 5V to 18V power to the VS connector to drive the servos. I used a 6v battery pack.
Also note that the on-board power switch did not appear to affect power to servo, so a power switch for the servo power is probably also useful.
External power source is required only at VM & GND terminals if jumpers are shorted both at VM+VIN and VS+5V, VM will have the same voltage as input power and VS (servo voltage) will be 5V derived from VM input, not from UNO board. That is what the user manual means by single power source, which input is at VM terminal. OPEN all the jumpers will need individual power source for VM and VS separately.

How many sensors will work at a time in an Arduino for Home automation?

As I am thinking to do a Home automation using Arduino, using Light sensor, temperature control , motion sensor , gas leakage sensor , fire detection sensor , hall effect sensor for Light on/off , fan on/off and fan speed control , motion detection , alarm for gas / fire detection , door open/close respectively.
But my question is how many sensors will work at a time in at an Arduino board?
And is it possible to control Arduino by using PIC or i.MX6 Dual Lite/Solo?
If the sensors use I2C then the limit is 128 devices on the bus, but they each have to have a unique address which are sometimes "hard-coded" on the device by the manufacturer. The Arduino Wired library is used to read/write I2C and it only takes two pins. I2C is also sometimes called TWI (Two Wire Interface). The PIC can do I2C, not so sure about the i.MX6 but I've controlled an Arduino over I2C using a Raspberry Pi.
For the Arduino Uno go here to find the specifications of the open source design:
http://arduino.cc/en/Main/arduinoBoardUno
There you will read that the Arduino Uno has 14 digital and 6 analog I/O pins.
Note, you are not limited to the number of sensors based on the number of I/O pins.
Example:
Any processor has a limited number of I/O pins. You can add hardware to multiplex external signals before they get to these I/O pins. For example, say the processor has 4 I/O pins. You can devote 3 to control a multiplexer selecting 1 of 8 signals to route to the 4th processor I/O pin. Thereby doubling the number of inputs you can sample.
You can use many number of sensors as you wish. But your board need to have that much I/O pins. Try to get mega Arduino board. Arduino Mega 2560 has 54 pins totally. So in the mega board you can connect many sensors.
You can also control the board by PIC, Arduino sketch and so on.

Bridge shield between Arduino and Raspberry Pi (to wirelessly upload the measurements of analog sensors to a webpage)?

I like to build a project to make my gardening work smarter! My goal is to measure soil temperature, soil water content, light intensity and also taking a picture, and then wirelessly upload these datasets to a webpage. I can also control the irrigation system (turn on/off the pump switch) via the webpage.
These sensors are anagogic! However, the Raspberry Pi Face (PiFace) Digital Interface is only able to take care of digital signals. The PiFace comes with the relaies, which is pretty handy for a startup project. I just like to get some premade boards and ensemble them easily without too work.
Can I layer up a Raspberry Pi board, an Arduino bridge shield, an Arduino board and a PiFace (or a relay board) without wiring?
I really need a recommended "shopping list" to start with. What should I choose?
I suggest you try following the steps outlined in Arduino and the Raspberry Pi.
I agree that you should involve an Arduino as your conduit to the outside world. Then do a simple serial connection between the two. If you get any Arduino except for the new Due, you have got to get from 5 V (Arduino) to 3.3 V (Raspberry Pi). I'd suggest Sparkfun's Logic Level converter.
Sparkfun also has a good light sensor, TEMT6000 Breakout Board.
While you're there, you can grab a couple of thermistors to measure temperature, Thermistor 10K.
Also, Make did an article on almost exactly what you intend on doing (from the Arduino side), Microcontroller-assisted gardening.
On the Raspberry Pi side, Pygame will give you a huge head-start on connecting to the Arduino and taking webcam shots. A Halloween Sound Trigger with Raspberry Pi and Arduino should get you started.
According to what you describe, you may achieve this with only an Arduino UNO, an Ethernet Shield, sensors (at least temperature and light) and a cheap CMOS camera.
If you want to take advantage of the two worlds (Raspberry with Arduino I/O capabilities), you may also consider the Raspberry Pi to Arduino shields connection bridge from Cooking-Hacks: they provide both library and tutorial to start with.

Resources