Weird behavior when using monitor and analogWrite (ESP32) - arduino

I'm currently working on a project where I want to vary the PWM to a motor given an input from a potentiometer. However, I cant seem to use the serial monitor and an analogWrite statement in the same program.
When I run this code I get this output from the serial monitor:
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.print("WORKING");
//analogWrite(1, 255);
}
void loop()
{
}
12:09:48.314 ->
12:09:48.314 -> WORKING
However, when I run this code (the only difference is that the analogWrite() line is no longer commented out), the serial monitor outputs garbage.
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.print("WORKING");
analogWrite(1, 255);
}
void loop()
{
}
{l$ܞ⸮⸮$⸮|⸮⸮l⸮#|⸮⸮⸮⸮{⸮#⸮"⸮⸮on⸮lon⸮⸮⸮#p⸮⸮bl`{lp⸮o⸮⸮l⸮⸮bo⸮|⸮⸮⸮#⸮⸮nN⸮$⸮⸮$`⸮on⸮{lor⸮⸮⸮⸮{r⸮ p⸮o⸮s⸮ܜ⸮⸮⸮#o⸮|⸮B⸮⸮on⸮⸮l ⸮No⸮{lor⸮⸮⸮Nrd`{⸮⸮N{d`⸮⸮⸮⸮⸮⸮$`⸮⸮N⸮l
⸮
Does anyone know why this is happening and how to fix it?
Not sure if it helps but im using an ESP8266 NodeMCU purchased from this amazing link: https://www.amazon.com/gp/product/B081CSJV2V/ref=ppx_yo_dt_b_asin_title_o07_s00?ie=UTF8&th=1

analogWrite(1, 255) is writting to GPIO1. If you look at the pin-out for the ESP8266 NodeMCU, GPIO1 is the TXD line for serial port 0 (it's labeled TXD0). I don't have a NodeMCU schematic handy, but port 0 is typically used for the serial monitor and wired to the USB-UART converter for that purpose. So by writing to GPIO1, you are interfering with the monitor output.
Try doing an analogWrite to a different GPIO, for example, GPIO5.

Related

AT works at half for HC05

I am currently trying to send my sensor data from my Arduino to an android app made on android studio using an HC05 module for Arduino.
I tried to configure the HC05 as every tutorial on the internet says, but i meet some problems.
I am using the arduino code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
int PotPin = A7;
int Vdata = 15;
void setup() {
Serial.begin(9600);
pinMode(9,OUTPUT); digitalWrite(9,HIGH);
Serial.println("Enter AT commands:");
mySerial.begin(38400);
}
void loop()
{
Vdata = analogRead(PotPin);
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
When I type "AT" in the Serial monitor, it returns me "OK" (that is normal).
But when I try to see the name/the address/the password of the module, it returns me "Error:(0)". The strangest thing is that the command " AT+NAME="NameWanted" " or even " "AT+PWD="4321" " works since it correctly changes the name of the module.
I looked on the internet but I didn't see someone with the same problem as mine, I hope someone will lead me to the solution!
Thanks
I found out what's the problem. My mcu's bauderate was bigger (115200), then my hc05's bauderate (38400). With this bauderate, my MCU sent the messages faster, then hc05 could read it. So, I decreased the bauderate of my MCU and now it's working

Can't see Serial.print() outputs in Visual Studio Code from Arduino device (ESP8266)

I can't see any Serial.print() outputs in Visual Studio Code from my Arduino device (an ESP8266 in this case). I was expecting to see it on the Debug Console. Do I have something configured incorrectly?
I know my code is working as the LED is flashing but I'm not seeing any output anywhere.
Here's my code:
#include <Arduino.h>
void setup()
{
Serial.begin(9600); // EDIT: added this line
Serial.println("Setup...");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
Serial.print("On!");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
Serial.print("Off!");
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
I am using this board:
https://www.waveshare.com/wiki/e-Paper_ESP8266_Driver_Board
Here is my platformio.ini file:
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
; Custom Serial Monitor port
monitor_port = COM4
; Custom Serial Monitor speed (baud rate)
monitor_speed = 9600
Near the bottom right of the VS Code screen is a little plug icon. Click that to open the serial monitor.
Set serial port baud rate in setup() by adding this code:
Serial.begin(SERIAL_BAUD_RATE);
For example:
Serial.begin(9600);
Finaly in serial port monitor set baud rate

Serial communication does not work on Intel Galileo Gen 2

I cannot get serial communication working on Intel Galileo Gen 2. I'm using Serial1 on port /dev/ttyS0 assigned to pin 0 and 1. For testing purposes I created loopback on that serial port (connected RX and TX together). Unfortunately, it seems that nothing works. After few test it seems that my board can receive data, but cannot send any.
void setup() {
Serial.begin(9600);
Serial1.begin(19200);
Serial.println("Ready");
}
void loop() {
while(Serial1.available() > 0) {
Serial.print(Serial1.read());
Serial.print(' ');
}
uint8_t buf[3] = {0xC0, 0xFF, 0xEE};
Serial1.write(buf, 3);
delay(2000);
}
I run same sketch with same configuration on Arduino Yún and it worked well. Where the problem could be? Thanks.
For this particular Galileo board, the baud rate for Serial object is always 115200 baud no matter the argument you give it. Since you connected Serial1 to Serial it could be just a synchronisation error due to different baud rate. Did you try to change this Serial1.begin(19200); to this Serial1.begin(115200); ?

Simulation of arduino mega 2560 with GSM Module using proteus

have really been suffering with my simulation! Tried connecting my arduino mega 2560 to COMPIM (used as GSM Module) in my circuit and also loaded sample code but damn! In vain! I wanted to view the data sent in virtual terminal but am getting nothing! and its also complaining of excessive CPU usage.
And thereafter, the messages are displayed as shown below.
Someone please help me out. Am I making a mistake oh? Infact the arduino code for displaying in the simulation is also giving me hard time. The one am using is as shown below.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
mySerial.println("Hello, world?");
if (Serial.available())
mySerial.println("Hello, world?");
}
Will b every grateful for any help offered.

CANbus simulation for Automotive purpose

i explain a bit...
I repair Electric powered steering systems for cars, especially Fiat/Alfa/Lancya (Delphi manufacturers) and i'm in need of making some tool to test these reparations, i mean just turning it on for example.
I have researched during some time, and i figured i need Can-bus signals to be simulated as the eps ECU is receiving ignition packets from CAN, here i go..
I need to know what way i could Read/Send CAN packets from/to BUS, i mean what tool or anything else. I have been trying with Arduino UNO + Sparkfun Shield, but i dont get any results, when everything connected, my serial console isnt sniffing any packets, i have connected all correctly i think, tried different bitRates, changed Arduino boards and shield, tried many different examples, i invested lots of hours with no profit... i was using Seat Ibiza 2010 for I+D, connected CAN-H AND CAN-L on OBD PORT, in the CAN lines from radio,etc...
Any idea of what could be wrong is welcome, as new method to make my project.. Thanks in advance!!
Info:
https://dl.dropboxusercontent.com/u/47864432/arduino/IMG_9358.JPG
https://dl.dropboxusercontent.com/u/47864432/canbus/LIBRARYS_USED.rar
There are two potential issues here:
H/W problem
CAN bus library problem
The first step is try loopback test. If all is OK, try CAN bus from any car OBD port, the speed should be 500Kb.
This one tries a couple of bus speeds -- works with sparkfun canbus shield:
#include <SPI.h>
#include <SD.h>
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
const int chipSelect = 9;
File dataFile;
void setup() {
// put your setup code here, to run once:
pinMode(chipSelect, OUTPUT);
Serial.begin(115200); // For debug use
Serial.println("CAN Read - Testing receival of CAN Bus message");
delay(1000);
if (Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 500k");
else if (Canbus.init(CANSPEED_250)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 250k");
else if (Canbus.init(CANSPEED_125)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok: 125k");
else
Serial.println("Can't init CAN");
delay(1000);
if (!SD.begin(chipSelect)) {
Serial.println("uSD card failed to initialize, or is not present");
return;
}
else {
Serial.println("uSD card initialized.");
delay(1500);
}
dataFile = SD.open("caninfo.txt", FILE_WRITE);
}
void loop() {
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
if (dataFile) {
int timeStamp = millis();
//write to uSD card
dataFile.print(timeStamp);
dataFile.print("ID: ");
dataFile.print(message.id, HEX);
dataFile.print(", ");
dataFile.print("Data: ");
dataFile.print(message.header.length, DEC);
for (int i = 0; i < message.header.length; i++)
{
dataFile.print(message.data[i], HEX);
dataFile.print(" ");
}
dataFile.println("");
Serial.println("Writing to SD");
}
else
{
Serial.println("Problem writing to SD");
}
}
}
}
If you want to communicate via CAN with Steering controller for example for an OEM like Delhpi .. this is not possible as the ECU (ELectronic control units) in the communication network are secured and the CAN protocol software decides who can participate and who can't.
As a tester tool you can read the trouble codes but you can't hack it to simulate the Ignition signal etc...

Resources