I have some knowledge of Arduino and a bunch of peripherals for same. I notice that others are making good progress in implementing peripherals for pyb, but I'm rather impatient and not a good enough coder to port things over.
So I'm using the following strategy: communicate with an Arduino via serial, and attach whatever peripherals I need to the Arduino. Since the mini Arduinos can be had via my friends "Michelle" and "Cindy" in China for only 3 Euros, this does not add much to the cost of my set up, compared to the cost of pyb.
Step one: modify boot.py
uart = pyb.UART(6,57600) #had to drop baud to decrease noise
pyb.repl_uart(uart)
(thanks Dave and Jon!)
Step two: connect the UART6 pins to Rx and Tx pins you are using on the Arduino. Don't forget to use a voltage divider or similar between the Arduino Tx and the pyb Rx, if your Arduino is running at 5v.
Step three: upload the Arduino code (appended below)
I had to add small delays to the main loop to get it to work properly. Not sure if there is a better way to do it. It would be nice if these delays can be taken out, but without them you get missed bytes.
Step four: play with pyb REPL via your Arduino, which is connected to your computer via usb. REPL should work at this stage.
Step five: write some small communication functions that send bytes across the serial channel. In my case the first thing I'm doing is using UIPethernet on the Arduino, so I can put my pyb on my local ip network. The additional modifications are pretty simple: replace the Serial.write and Serial.read in the Arduino code with almost identical UIPethernet routines.
Step six: enjoy!
------------------------------
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
#define baudrate 57600
SoftwareSerial Soft = SoftwareSerial(rxPin, txPin); // RX, TX
void setup() {
// initialize serial communication at baudrate bits per second:
Serial.begin(baudrate);
while (!Serial) {;} // wait for serial port to connect. Needed for Leonardo only
// set the data rate for the SoftwareSerial port
Serial.println("Serial started");
// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
Soft.begin(baudrate);
Serial.println("SoftSerial started");
}
void loop() {
if (Soft.available()) {
Serial.write(Soft.read());
delay(1);
}
if (Serial.available()) {
Soft.write(Serial.read());
delay(1);
}
}
taking the low road to implementing peripheral devices
-
- Posts: 4
- Joined: Sat Nov 08, 2014 1:44 am
Re: taking the low road to implementing peripheral devices
I know this is an old post, but it may help others who get here by searching the forum as I have.
You may run in to issues if your 5V part is supplied with more than 5V or your 3.3V part is supplied with less than 3.3V though. Many 5V parts are good to run at 5.5V, but that may damage the 3.3V (5V tolerant) pin. Many 3.3V parts are capable to run below 2V, but that won't trigger a HIGH on the 5V part.
These are things to consider especially if you're running on batteries with no regulator.

You may need to check the specific chip you're using, but on the pyboard (stm32f40x chips), UART6 is on PC6 (TX), and PC7 (RX) which are 5V tolerant pins (as are most of the pins). You don't need any voltage divider or anything. Generally speaking, 5V microcontrollers consider 3.3V (usually anything over about 2.6-2.7V) as a high value.Step two: connect the UART6 pins to Rx and Tx pins you are using on the Arduino. Don't forget to use a voltage divider or similar between the Arduino Tx and the pyb Rx, if your Arduino is running at 5v.
You may run in to issues if your 5V part is supplied with more than 5V or your 3.3V part is supplied with less than 3.3V though. Many 5V parts are good to run at 5.5V, but that may damage the 3.3V (5V tolerant) pin. Many 3.3V parts are capable to run below 2V, but that won't trigger a HIGH on the 5V part.
These are things to consider especially if you're running on batteries with no regulator.