I am trying building a project that requires me to use 6 UART connections. For this I have chosen the STM32F030CCT6 MCU, which supports 6 USARTs. I have gotten all 6 to work in the STM CubeIDE, but have decided to switch over to the Arduino IDE because I would like to use a few libraries.
In Arduino, I am using the latest Arduino_Core_STM32 api.
The api doesnt specify the suport for this exact chip, but it lists supports the STM32F030C8T6 chip, which for all intents is the same, with the only difference that it supports only 3 USARTS. I have tried using both HardwareSerial and SoftwareSerial libraries to add uarts, but when I add more then 2 UARTS the code compiles, uploads and executes until the first UART and then just "hangs" until I reset the chip.
My question is if I can somehow modify the library/get a different library that supports all 6 USARTS of this chip.
Alternativly, is it possible to use the working code generated in MXCube in Arduino and use the USART that way?
Or is this just a problem with Arduino_Core_STM32?
used settings to program
code:
#include <EthernetENC.h>
#include <HardwareSerial.h>
#include <SoftwareSerial.h>
HardwareSerial mySerial1(PA5,PA4); // compiles, can also use (USART1)
HardwareSerial mySerial2(PB11,PB10); // compiles, can also use (USART2)
HardwareSerial mySerial3(PA10,PA9); // compiles
void setup() {
pinMode(PB15, OUTPUT); //CP WRITE 34
digitalWrite(PB15, LOW);
}
void loop() {
digitalWrite(PB15, HIGH);
delay(500);
digitalWrite(PB15, LOW);
delay(500);
mySerial1.begin(9600);
mySerial1.println("Hello, world?");
mySerial1.end();
mySerial2.begin(9600);
mySerial2.println("Hello, world2?");
mySerial2.end();
mySerial3.begin(9600);
mySerial3.println("Hello, world3?");
mySerial3.end();
}
Thank you to everyone for the insight, learned a lot of new things.
I managed to get all 6 USARTS to work by creating a new board variant.
The port map files were already present for this board (and many others )in the
AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.3.0\variants folder.
I just edited the boards.txt file to add the F030CCT folder and created a .ld file in MX cube and added it to the folder. The board now behaves like it should and all the pins and functions work great.
I just changed the top part of the code to:
HardwareSerial SerialX(USART1);
HardwareSerial SerialY(USART2);
HardwareSerial Serialz(USART3);
HardwareSerial SerialX2(USART4);
HardwareSerial SerialY2(USART5);
HardwareSerial Serialz2(USART6);
Related
When I run this code, I only get a high temperature as shown in the following picture.
How do I connect the pins to work properly?
A0-SIM
A1-RST
Can you explain it this way?
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup() {
Serial.begin(9600);
Serial.println("Adafruit MLX90614 test");
mlx.begin();
}
void loop() {
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF());
Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
Serial.println();
delay(500);
Your sensor is using Serial communication interface, while Adafruit library is using I2C interface. So you can't use that library.
You need to connect Tx to Pin 10 on Arduino Uno, and Rx to Pin 11, and run the sketch shows here.
The Adafruit library is for a bare sensor or sensor module with an I2C connection, but the module you have uses a serial connection.
If you want to use the Adafruit library as-is, you need to get a module or sensor that can connect over I2C (one that has pins marked SCL/SDA).
If you want to use the module you have, you need to find an Arduino library that supports it (I don't know of one), or do some programming yourself.
So I'm using an ESP32 with a TTGO display (see image below for pinout) and I want to use the RC522 RFID module, however, I'm getting a communication error and the firmware version is unknown. I'm using the Arduino IDE, SPI library and MFRC522 library.
I've spent the whole day scouring the internet, I've read numerous posts on forums and tried the solutions that were provided (such as: solder the pins, check the wiring again ...). I've also read and watched countless tutorials, all to no avail. When I tried to use the RFID module on the Arduino UNO, everything worked great, but I have to use the ESP32. I feel like I've tried everything so I'm just hoping that someone has had the same issue and found a solution.
Below is my code, it's the DumpInfo example of the MFRC522 library, modified a tiny bit because - as I said- i've tried a bunch of 'solutions'. The RC522 has 8 pins: 3.3V, GND, RST, RQ, MOSI, MISO, SCK and SDA. The 3.3V is connected to the 3.3V of the ESP32, GND to GND of the ESP32. RST is the reset pin which is connected to GPIO22 (defined as RST_PIN). SDA is the slave select pin which is connected to GPIO21 (defined as SS_PIN). Then there's the SCK, MOSI and MISO pins which are connected respectively to GPIO25, GPIO26 and GPIO27 (defined as SCK_PIN, MOSI_PIN and MISO_PIN). The RQ pin is used for interrupts which we don't need, so it's not connected to anything.
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 22 //GPIO22
#define SS_PIN 21 //GPIO21
#define MISO_PIN 27 //GPIO27
#define MOSI_PIN 26 //GPIO26
#define SCK_PIN 25 //GIPO25
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
SPIClass spi(HSPI);
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
spi.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
spi.setDataMode(SPI_MODE3);
mfrc522.PCD_Init(); // Init MFRC522
delay(5000); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
This results in a few random symbols and then the following in the serial monitor:
Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Scan PICC to see UID, SAK, type, and data blocks...
As I mentioned, this is sort of a last resort. I'm hoping someone has been in the same situation and could provide some useful info that I hopfully haven't already read somewhere.
I was at exactly the same situation as you were: my MFRC-522 was working fine on the Uno, but it did not work on the ESP32. I came here for help, and your question led me in the correct direction. In my code, the arguments for the SPI.begin() call were missing: SCK_PIN, MISO_PIN and MOSI_PIN. Without those arguments, my ESP32 could not read the data. I have tested and confirmed that the pinMode(SS_PIN, OUTPUT) and spi.setDataMode(SPI_MODE3) calls are not necessary for it to work, but passing the arguments as you did on SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN) is mandatory.
I'm using different pin numbers, it's the only difference between my working code and yours. Here's my defines:
#define RST_PIN 22
#define SS_PIN 21
#define MISO_PIN 19
#define MOSI_PIN 23
#define SCK_PIN 18
I realize you must not be reading this, but I hope I can help someone as you have helped me. Thanks!
Bruno
I'm trying to use the Adafruit Fona Mini GSM together with the Nucleo L073RZ. There exists a library for the GSM module, but it's for arduino. I've setup the board manager url to make use of the link in this repository: https://github.com/stm32duino/Arduino_Core_STM32/blob/master/README.md to add support for the MCU I'm using.
It's not possible to use SoftwareSerial together with this MCU it seems like. The library disappears when the card is selected. The GSM library supports HardwareSerial by uncommenting some lines though, which I've done. Unfortunately the MCU is unable to communicate with the GSM module.
Tera Term image
This is how everything is connected.
Hardware image
In case it's not apparent by the picture, this is how the GSM module connects to the MCU.
Vio connects to 5V
GND connects to GND
RX connects to TX/D1
TX connects to RX/D0
This is the only code modification I've made in the FONATest example, just to use hardware serial instead of software serial.
// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three
lines
// and uncomment the HardwareSerial line
//#include <SoftwareSerial.h>
//SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
//SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
HardwareSerial *fonaSerial = &Serial1;
so I got my Arduino Uno today. For a porject I want to be able to control some relays on my Arduino via Wifi (via Blynk app). For this I want to use the ESP8266-01 as a Wifi shield.
I used this tutorial: https://create.arduino.cc/projecthub/nolan-mathews/connect-to-blynk-using-esp8266-as-arduino-uno-wifi-shield-m1-46a453
Only difference is I'm using Win10. Here is what I got:
Arduino Uno R3
Arduino IDE 1.8.1
included all Blynk/ESP libraries and installed ESP8266 as board (generic)
uploaded empty sketch to the Arduino
Connections to Between Arduino/ESP as follows . http://www.teomaragakis.com/hardware/electronics/how-to-connect-an-esp8266-to-an-arduino-uno/ (I know about to 3.3V to 5V issue but seems to work so far)
Okay, first problem is that I couldnt flash the Firmware of the ESP (got it from Sunfounder) as said in the Tutorial. Downloaded the latest firmware and flashed it with ESP8266Flasher.
Other Problem that is when I try to compile the code from the first tutorial, I always get error :
C:\Users\Chris\Documents\Arduino\libraries\Blynk\examples\Boards_WiFi\ESP8266_Shield\ESP8266_Shield.ino:5:21: fatal error: ESP8266.h: No such file or directory
As said I have installed all libraries. Cant really think of things to do anymore. Any help would be much appreciated. Best regards from Berlin, Chris.
To close the code I try to upload to the board (both Arduino Board or generic ESP8266 does not work)
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266.h>
#include <BlynkSimpleShieldEsp8266.h>
// Set ESP8266 Serial object
#define EspSerial Serial
ESP8266 wifi(EspSerial);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "???";
void setup()
{
Serial.begin(115200); // Set console baud rate
delay(10);
EspSerial.begin(115200); // Set ESP8266 baud rate
delay(10);
Blynk.begin(auth, wifi, "???",
"???");
}
void loop()
{
Blynk.run();
}
The ??? I switched for my token and data ofc.
Try changing this
#include <ESP8266.h>
to this
#include <ESP8266_Lib.h>
The file was renamed in this commit.
I have an Arduino Mega 2560.
I want to connect it to ESP8266 aka ESP 01 module.
First i open and compile an empty sketch. When i start serial monitor, i write AT commands (like connect with WIFI) in serial monitor and i click on send button. In this case all works fine.
After I tested that the commands works properly , I want to write an Arduino sketch in which I implement the function to automatically send command without writing it in serial monitor.
For this purpose, i write this code:
#define SSID "test"
#define PASS "1111"
void connectWiFi() {
Serial.write(“AT+CWJAP=\"SSID\",\"PASS\"");
}
void setup() {
Serial.begin(9600);
connectWiFi();
}
void loop() {
}
When i try to execute the code in Serial monitor, it is printed only the string but the command does not work.
Why when i write this command in serial monitor works and when i try the code above, the command does not work?
Is there a way to pass and execute a command from arduino sketch? What is the problem in my code if is wrong?
Thanks in advance for response.
Sorry for my English.
Serial.write(...) makes arduino write through its serial ports (i.e. USB or pins 0 and 1). A better way to make Arduino send instructions directly to ESP is by defining "software serial" pins to communicate with ESP.
You'll need to include SoftwareSerial.h and use SoftwareSerial esp8266(2,3); for example to make pins 2 and 3 communicate serially with ESP.
Your code should look something like this:
#include <SoftwareSerial.h>
#define SSID "test"
#define PASS "1111"
SoftwareSerial esp8266(2,3);
void setup(){
Serial.begin(9600);
esp8266.begin(9600); //ensure this baudrate is similar to your ESP's
delay(500); //give it some time
esp8266.println(“AT+CWJAP=\"SSID\",\"PASS\""); //send to ESP this way
}
void loop(){
if(esp8266.available()){
while(esp8266.available()){
Serial.write(esp8266.read()); //make serial monitor print what ESP sends
}
}
}
You can also refer to this example for further detail