Using PyCom boards with Arduino IDE
-
It appears to be easy to use PyCom boards with Arduino IDE.
I'll show here an example for my FiPy, you have to adjust the instructions if you want to use it with other boards.
Disclaimer: continue at your own risk! (This is not officially supported)
First of all, here is a list of prerequisites you need to start with:
- Install Arduino IDE
- Install ESP32 Arduino core package
- Be able to build (verify) a simple sketch for ESP32. Select
Tools->Board->ESP32 Dev Module
.
Next, I had to create a simple list of pin definitions for my peripherals (according to FiPy pinout).
You can (for example) include it on the top of your sketches for simplicity of use.#define LED_WS2812B 0 #define LTE_RTS 32 #define LTE_TX 33 #define LTE_RX 34 #define LTE_CTS 35 #define LORA_WAKE 38 #define LORA_SS 18 #define LORA_CLK 5 #define LORA_MOSI 27 #define LORA_MISO 19 #define LORA_INT 23
RGB LED example
Let's start with a simple RGB led example (for this you need to install the FastLED library):
#include "FastLED.h" #define NUM_LEDS 1 CRGB leds[NUM_LEDS]; void setup() { // Set console baud rate (not used here) Serial.begin(115200); // Init RGB LED FastLED.addLeds<WS2812B, LED_WS2812B, GRB>(leds, NUM_LEDS); FastLED.setBrightness(32); leds[0] = CRGB::Black; FastLED.show(); delay(1000); } void loop() { leds[0] = CRGB::Red; FastLED.show(); delay(500); leds[0] = CRGB::Green; FastLED.show(); delay(500); leds[0] = CRGB::Blue; FastLED.show(); delay(500); leds[0] = CRGB::Black; FastLED.show(); delay(500); }
Next I connect my
G23 -> GND
+ push a reset button on my FiPy to enter the firmware update mode.The board is connected via USB cable, so I select the corresponding
Tools->Port
and hit Upload:
If upload is successful. disconnect the G23 jumper and reset the board.
Yaaay - it should starts blinking an RGB.LTE modem example
#define SerialAT Serial2 void setup() { // Set console baud rate Serial.begin(115200); // Set LTE modem Serial SerialAT.begin(921600, SERIAL_8N1, LTE_RX, LTE_TX); pinMode(LTE_RTS, OUTPUT); digitalWrite(LTE_RTS, LOW); } void loop() { while (SerialAT.available()) { Serial.write(SerialAT.read()); } while (Serial.available()) { SerialAT.write(Serial.read()); } delay(1); }
Now I'm able to send some AT commands directly to the modem:
What's next?
- Other examples for Arduino & ESP32 should work, like working with the LoRa module, you could try playing with it.
- It should also be easy to control your board over BLE or WiFi with Blynk.
- I'm rather interested to integrate this LTE modem into my TinyGSM library, but unfortunately can't get it working even with default examples (probably some LTE service provider problem here).
- You should also be able to run JavaScript (Espruino), or Espressif IDF (official ESP32 SDK) in the same way.
Returning to normal
Oh, almost forgot to mention! If you want to restore the MicroPython on your board, just follow the PyCom firmware upgrade guide. It will bring the power of Python back to you ;)
Why?
I find it useful, at least for:
- Educational purposes
- Checking peripherals/modules (i.e. there's an ready-to-use Arduino driver/example available)
- Having advanced control over the board capabilities (especially if using IDF)
-
I'm getting this error whenever I try to compile anything for the GPy:
[15975] Error loading Python lib '/var/folders/57/hyd6ntr1233_x_brscxdp8480000gn/T/_MEI7xbrkg/libpython3.8.dylib': dlopen: dlopen(/var/folders/57/hyd6ntr1233_x_brscxdp8480000gn/T/_MEI7xbrkg/libpython3.8.dylib, 10): Symbol not found: ____chkstk_darwin Referenced from: /var/folders/57/hyd6ntr1233_x_brscxdp8480000gn/T/_MEI7xbrkg/libintl.8.dylib Expected in: /usr/lib/libSystem.B.dylib in /var/folders/57/hyd6ntr1233_x_brscxdp8480000gn/T/_MEI7xbrkg/libintl.8.dylib
I have just re-installed Python 3.9.
Anyone know how to fix this?
-
@Clemens said in Using PyCom boards with Arduino IDE:
Would be also interested to use FiPy or GPy with TinyGSM for Arduino
hi, you may look here: https://github.com/vshymanskyy/TinyGSM/issues/579
bye, pottendo
-
Would be also interested to use FiPy or GPy with TinyGSM for Arduino
-
@Lonefish
Hello, did you finally able to use TinyGSM with FiPy or GPy in order to call servers?
-
@Lonefish Ever get TinyGSM working? I need to sent CoAP UDP messages with it. I've used TinyGSM with other Arduino computers on standard ublox cell modules but new to narrow band.
-
I'm using this library at the moment, I can attach and connect to the network, but my efforts fail when I want to do some actual calls to servers. I don't seem to have http-traffic:
-
@Volodymyr I'm restarting my efforts to get this working again. Have been jumping from POC to POC. But we're switching to esp-idf instead of Arduino. Although, once it's working in esp-idf, it'd be an easy port to arduino back probably.
ATM I'm still at the "having communication" part, no actual internet connection yet, but just started working on it again.
-
@Lonefish I'm wondering if you got this working ;)
I have updated the OP use the Serial2.
-
@mattt said in Using PyCom boards with Arduino IDE:
I did have to add
#define SerialAT Serial2
That seemed to work indeed! Sending AT+CSQ replied with 99,99 which is no connection. Haven't tried it any further, but it's more than I had a few months ago ;) Thanks!
EDIT : There was no antenna connected nor was there a SIM inserted, so the 99,99 is logical.
-
Have anyone managed to do it with a Gpy ?, I have been trying without success
I am defining the UART pins as :
#define LTE_TX 23 #define LTE_RTS 18 #define LTE_RX 5 #define LTE_CTS 19
-
I did have to add
#define SerialAT Serial2
@Lonefish said in Using PyCom boards with Arduino IDE:Did you use the exact same code
-
@Lonefish I tried using that code and the code in this pull request against the TinyGSM library, same result. Almost like the modem is locked until it receives a certain command.
-
@mattt I never even had an OK back. Did you use the exact same code?
-
Has anyone had success with this? When running the above code, I get an "OK" in response to "AT" but every other code that I've tried results in an "ERROR" response from the modem.
-
thanks @Volodymyr for you post, i'm trying to see if i can use lopy4 with the arduino ide (or platformio) and i wonder where to find the doc or the code to run sigfox functions in cpp. Can you give me a hint ?
-
I'm not sure if topicstarter is still on Pycom, but I can't seem to get this to work. The first example doesn't build because of the FastLED library, but I can make it a hello world that just prints over serial.
So the arduino part works. I do have a problem communicating with the LTE modem tho, as in, it doesn't reply at all. Did something change in firmware on the fipy/modem/...?
-
@jmarcelino Thx. Updated my post to reflect this.
-
@volodymyr
Thank you for your post. Yes it's possible to run any ESP32 environment such as the Arduino however this isn't officially supported by Pycom.