Pi-Arduino Integration question

On the subject of Raspberry Pis - for whoever knows about this:

I use two Megas to run my inMoov with MRL and (generally) Windows.  I am adding some wheels to the base and am considering throwing one of my pi family in there just to run the wheels, rather than use an Arduino Nano or similar.  I might even put a pi-zero in the head for some duties. 

BUT- it now occurs to me that, even though we have a Raspberry Pi service in MRL, the pi is a computer not a micro-controller. 

Is it possible to integrate it into the running of MRL, in concert with the existing Arduinos, simply, using the same script in MRL, run from my main Windows computer, without having head-aches?  Is anyone already doing this? It's pretty straight-forward to run the whole robot from Pi but is integration in this way possible?

I don't want to change over to Raspberry Pi for the whole robot as I'm happy with the Arduinos/PC set-up. 

If people are using the service, how are they using it in MRL?

Advice appreciated.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
GroG's picture

Mats is the most experienced

Mats is the most experienced in this area.

We all have been working together to try to make the switching of components (such as switching from Arduino's to RasPi + I2c) as "easy" as possible.  Mats has done a significant amount of work to this end.

Personally, I like the general architecture of RasPi + I2c over Arduino.  

  • Wiring is cleaner/simpler
  • There is no more mrl "sketch"
  • Network distribution of multi-mrl instances really excites me :)

Right now the distirbuted network is a mess, because I'm in the middle of refactoring the hell out of it.  It will be much more powerful and much easier to get working when I'm done.  So, headache free ... not yet .. but that's my primary focus now.

That's not to say I don't love Arduinos - especially with the ESP_8266 wifi Arduinos for $6.  These little guys I'd like to automate all my house with, but they are probably not a very good choice for InMoov.

I'll defer to Mats for the current state of Pis & I2C controllers.

Humanoid's picture

Hmm. Networking. Sounds interesting

Thanks Grog.

Sounds like we don't quite yet have the technology.  It appears I should stick to the current set-up for the time being and throw in a couple more Arduinos.  

I could just run my wheels separately with a non-integrated pi or integrated with an Arduino, unless the Uber-Mats has some suggestions.  

 

 

Mats's picture

Raspberry PI

The Raspberry Pi is quite a bit more powerful than the Arduino, even if it's not as powerful as a PC. Running servos on the PI is supported today by using the Adafruit16CServoDriver. You can read more about how to connect it here: http://myrobotlab.org/service/adafruit16cservodriver.

In MRL you use the servo service exactly the same way you would do with and Arduino. The only exception is that you attach to the Adafruit16CServoDriver service instead of the Arduino. And the Adafruit16CSevoDriver attached to the RasPi sevice. That's all.

The reason I like using the Raspberry is that it has i2c GPIO pins.

So what is that i2c ? It's a serial protocol where you can connect many different devices to the same two pins. So if you want to have more than 16 servos, you just add one more board.

And the boards dont' have to be of the same type. So you can mix many differnt boards on the same two wires as long as they don't use the same address. And most board can change address if needed.

So for example, I use one servo board in the arm of my InMoov. And the plan is to add one or more ADS1115 boards ( Analog to digital converters ) and an MRP121 ( capacitive sensor ) to the hand. No extra wires thru the arm / shoulder. The plan is also to put an MPU6050 ( gyro/accelerometer) in the hand to know it's orientation. 

The list of i2c services supporten in MRL is getting longer. 

The services that use i2c today are:

Adafruit16CServoDriver. ( Used to drive up to 16 servos, or 8 motors )

AdafrutIna219 ( Voltage and Current sensor )

Ads1115 ( Analog to digital converter )

Bno055 ( Gyro and accelerometer )

I2cMux ( If you need more addresses this board supports adding 8 more i2c buses ( 128*8 addresses )

Lm75a ( Temperature sensor )

Mpu6050 ( Gyro and accelerometer )

OledSsd1306 ( OLED display 64*64 pixels ).

Pcf8574 ( 8 bit IO expander )

And the nice thing is that yo can connect all these different devices in three different ways.

1. Using the i2c pins on the Arduino

2. Using the GPIO pins on the Raspberry PI

3. Using the io pins on the Esp8266_01 

All of this is worky in MRL today. 

And I have a list of at least 7 other devices that I want to add.

So most of my work is focused on adding support for more sensors, since I think sensing the environment is critical for any robot. 

------------------------------------------------

To add a bit to GroG's love for the esp8266, you could go for something very simple for the wheeled platform.

Using an ESP8266_01 together with one servoboard would not only be very cheap, but you could control the wheels from your ordinary MRL instance, just using 2 more servo services,an Adafruit16CServoDriver service, and one ESP8266_01 service.  

If made two videos about how to use the ESP8266_01 as an i2c controller, and how I used it to build a WiFi gamepad.

https://www.youtube.com/watch?v=NKWsHuB5Gak

https://www.youtube.com/watch?v=xUeeHOz--QQ

All software for this is included in MRL today, and has been so for a few months.

-----------------------------------------------------------

 

Humanoid's picture

Awesome possibilities

Thanks, Mats, for taking the time to provide all that info. 

I have one of those Adafruit Servo Drivers so I should get around to using it.  It seems that the 16C doesn't run DC motors, which are the ones I have. The Adafruit website says this. 

I know how to control 4 DC motors (not stepper motors, just 2 wire motors) directly from the Pi using an L298N driver board. Is it possible to do this integrated into the same python script in MRL that controls the Arduinos, using the pi and no shield - just the L298N? 

I will definitely investigate all your solutions and ideas.  I really like both the Pis and the Arduinos so it will be good to integrate them. I know jack about i2C so I need to study up more on that.

The wifi options are very alluring. I'm learning to hate wires. They're driving me up the wall in my inMoov's back and neck, especially now that I have installed switches, amp & speakers.  Apparently we don't have a service to communicate with my Arduino Uno Wifi, even though it's an ESP8266. Wish I could figure out how to make that work as an integrated service in MRL.

Seems that you are on the cutting edge of inMoov development with what you are doing and we are all benefiting from your experimentation and knowledge. 

Thanks, again.

Mats's picture

Motors and Adafruit16CServDriver

Hi Humanoid

The 16C servoboard is a generic pwm generator, so it can control LED's, servos and also DC motors. To you can connect the 16C servoboard to the L298N board and use the Motor service. 

http://myrobotlab.org/service/Motor

Only problem with this is that C16 only can use one pwm frequency, and seros requires the board to run at 50hz and that's a bit low for a motor. So basically you can't mix motors and servos on the same board.

The Motor service has been changed to be two different Motor services. So the L289N would use the MotorDualPwm service instead of the Motor service. The GUI needs to be updated for the DualPwm service.

It should also be possible to drive both servos and motors from the GPIO pins of the Raspberry, but currently that's not supported from MRL. New thing to put on the TODO list :)

I think it would be very nice to only need a single computer ( RasPi ) and no other microcontroller.

 

Humanoid's picture

Awesome, and what about....

Thanks, Mats,

That top option you just gave there sounds interesting.  

I just found this pi hat on the Adafruit website. 

https://learn.adafruit.com/adafruit-dc-and-stepper-motor-hat-for-raspber...

This hat can run four DC motors and steppers. 

Do you think this hat would integrate in MRL or would I need a service we don't have yet?

Do you think this would have enough grunt to run the four DC motor wheels? It looks like you can put 12 volts into it too. 

It looks like what I need for my wheel base. If so I might invest.

Mats's picture

Nice HAT

First I was thinking that it would work out of the box, since it contains the same PWM chip ( PCA9685)  as several other boards that are supported in MRL. But reading the code I see that they use 3 pins for each motor and that the addresses are different. I would expect the default address to be 0x40, but the documentation and code states 0x60. And they also have an EEPROM on the board with the address 0x50. Not sure how it is used. So I'm a bit confused about how it works. 

So it needs a new motor driver in MRL.

However it should not be hard to make new drivers for that HAT. I checked with my local electronics supplier and he has that board in stock, so I could get one in a few days.

My concern with that board is that it only supplies 1.2A ( max 3A ). Even on a 12V system that limits the power to 14W. Not much for a motor. I tested using a drill motor and the L298N board and the thermal protection kicked in immediatley. The type of drivers I use now are much more powerful. 

I use two different types:

IBTS7960B

BT-4 50A 

Just search on Ebay and you will find them.

With them you can use much more powerful motors.

 

 

Humanoid's picture

Adafruit Pi motor hat.

Mats, 

I just ordered one of those shields on ebay.  Couldn't resist a new toy.  I'll test it out and see how it goes. I'd be keen to know what you thought if you tried it too. 

Did you see this on the website?

------------

"Voltage requirements:

The first important thing to figure out what voltage the motor is going to use. If you're lucky your motor came with some sort of specifications. Some small hobby motors are only intended to run at 1.5V, but its just as common to have 6-12V motors. The motor controllers on this HAT are designed to run from 5V to 12V.

MOST 1.5-3V MOTORS WILL NOT WORK or will be damaged by 5V power"

-------------------

I think the DC motors I've got are 6 volt. You don't think it would work with them?  

Was the code you were reading from the stepper motor inputs or the DC motor inputs?  There are both types on that shield.

Did you see the down-loadable pdf on the site? Link is at the left on the web-page.

Adafruit's awesome. 

Mats's picture

Code

I was reading this code:

https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library/blob/maste...

It contains the logic for both the DC mmotor and the setppers.

I also looked at this schema to understand how it works.

https://cdn-learn.adafruit.com/assets/assets/000/022/655/original/raspbe...

6V motors DC motors should work fines. 

Seems like I have to order the same shield, to be able to test how it works and add the necessary support for it in MRL.

 

Humanoid's picture

Stepper/DC Motor shield

Mats,

That would be really awesome if you did that. 

I think that shield would be a great service for MRL. Lots of options without complications.

It's difficult to get things working without dramas when you are just learning. I'm sure I'm not the only one who'll benefit.

Thanks very much.