Trouble with sending data through Serial2 in esp32 - esp32

I need to send hex data from esp32wroom to a relay module. The communication is via RS485. The RS485 module used in SN75H12VD.The Rx and Tx pins are 16 and 17 of esp32. The enable pin is connected to pin 4. I have made the enable pin HIGH. I tried to use hardwareserial. Used a serial terminal to check whether the data is being sent. But nothing is getting printed. I also tried Serial2. But no luck. Please find my code below. It would be great if someone could help me with this.
#include<Arduino.h>
#include <HardwareSerial.h>
#define RXD2 16
#define TXD2 17
#define enable_pin 4
HardwareSerial mySer(2);
void setup()
{
Serial.begin(115200);
Serial.println("hi");
mySer.begin(9600, SERIAL_8N1, RXD2, TXD2);
pinMode(RXD2, INPUT);
pinMode(TXD2, OUTPUT);
pinMode(enable_pin, OUTPUT);
delay(10);
digitalWrite(enable_pin, HIGH);
}
void loop()
{
if (!mySer)
{ // If the object did not initialize, then its configuration is invalid
Serial.println("Invalid pin configuration, check config");
while (1) { // Don't continue with invalid configuration
delay (1000);
}
}
else {
Serial.println("hello");
mySer.println("hey");
mySer.write(0x13);
mySer.write(0x01);
mySer.write(0x03);
mySer.write(0x40);
mySer.write(0x02);
mySer.write(0x01);
mySer.write(0x00);
mySer.write(0xC9);
mySer.write(0x80);
mySer.write(0x0A);
delay(2000);
mySer.write(0x13);
mySer.write(0x01);
mySer.write(0x03);
mySer.write(0x40);
mySer.write(0x02);
mySer.write(0x00);
mySer.write(0x00);
mySer.write(0xC8);
mySer.write(0x10);
mySer.write(0x0A);
delay(2000);`enter code here`
}
}

Related

How to connect TI - CC1101 to NodeMCU Board

I'm trying to get the TI-CC1101 433 MHz Transceiver Module to work with my NodeMCU ESP8266 but I am not sure about the wiring.
Link to the data sheet: LINK
Heres is a link with picture:LINK
I only want to use this Transceiver as a receiver for now so that's my setup:
NodeMCU 3.3 Volt --> VIC of TI-CC110
GND --> GND
NodeMCU D4 (2 in Arduino IDE) --> SI pin of TI-CC110.
I tested the following code with another 433 MHz receiving unit and it worked.
It's the example code of the RC Link Library:
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(2); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
}
mySwitch.resetAvailable();
}
}
I get nothing when I'm trying the new module wired the way described above.
Hello the rc switch library does not support the cc1101 module officially. but there is an external driver library which allows to use the cc1101 module with rcswitch. Currently the esp modules are not supported. an update for esp is in planning.
https://github.com/LSatan/RCSwitch-CC1101-Driver-Lib

Arduino speaker using sd card code error

I have basically connected a speaker to Arduino uno board. I just need help with the code. I have used the TMRpcm library to make it easier. However, it seems to be giving me an error everytime. here is the code below.
include "SD.h"
define SD_ChipSelectPin 10
include "TMRpcm.h"
include "SPI.h"
TMRpcm audio;
void setup(){
audio.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
audio.setVolume(10);
audio.play("Spring_In_My_Step_-_Silent_Partner_Mp3Converter_ne.wav");
}
void loop()
{
}
any and all help is appreciated
thank you!

Solving "redeclared as different kind of symbol" error

I'm currently working on Arduino. I'm working for Lamp using Atmega1284. I saw an example code, ModbusIP_ENC28J60 -> Lamp. I first compiled it without adding anything, it compiled properly. Now, I'm adding WebSocketServer, since I want this to work on websocket too. I added few necessary lines, but I ended up with this error:
error: 'EthernetClass Ethernet' redeclared as different kind of symbol
I don't understand what's wrong with the code or what I should change. Can someone help me with this?
I'm pasting my code here for reference:
#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>
#include <WebSocketsServer.h>
WebSocketsServer webSocketServer = WebSocketsServer(8080);
//Modbus Registers Offsets (0-9999)
const int LAMP1_COIL = 100;
//Used Pins
const int ledPin = 9;
//ModbusIP object
ModbusIP mb;
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
switch(type) {
case WStype_DISCONNECTED:
Serial.println("[%u] Disconnected!\n");
break;
case WStype_CONNECTED:
{
//IPAddress ip = webSocket.remoteIP(num);
Serial.println("[%u] Disconnected!\n");
// send message to client
//webSocket.sendTXT(num, "Connected");
}
break;
case WStype_TEXT:
Serial.println("[%u] got text!\n");
// send message to client
// webSocket.sendTXT(num, "message here");
// send data to all connected clients
// webSocket.broadcastTXT("message here");
break;
case WStype_BIN:
Serial.println("[%u] get binary ");
//hexdump(payload, lenght);
// send message to client
// webSocket.sendBIN(num, payload, lenght);
break;
}
}
void setup() {
// The media access control (ethernet hardware) address for the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address for the shield
byte ip[] = { 192, 168, 0, 120 };
//Config Modbus IP
mb.config(mac, ip);
//Set ledPin mode
pinMode(ledPin, OUTPUT);
// Add LAMP1_COIL register - Use addCoil() for digital outputs
mb.addCoil(LAMP1_COIL);
webSocketServer.begin();
webSocketServer.onEvent(webSocketEvent);
}
void loop() {
//Call once inside loop() - all magic here
mb.task();
//Attach ledPin to LAMP1_COIL register
digitalWrite(ledPin, mb.Coil(LAMP1_COIL));
webSocketServer.loop();
}
Help me to make it work.
You are declaring Ethernet twice. And they are different.
First is probably in the include file Ethercard.h
Second is Modbus.h
In the ModbusIP_ENC28J60 I found in github via Google they declare Ethernet as an array.
Either rename one declaration (e.g. ether vs Ethernet) or eliminate the use of one. Also, considering the include files in your source I would be surprised if there are only two conflicts.
C lesson: Declaring a variable for use by a function, very straightforward. When adding additional modules any name conflicts will cause problems. If you get two variables to agree but are still in the program you will suffer massive debugging headaches because one function will access its variable while the other will have its own, resulting in nothing actually working.
Go back and look at the source files (*.h). Search for "Ethernet" variables. See how they are declared and how they are used. The simplest solution is to pick the latest addition and change Ethernet to ether (as I suggested above).
Good Luck.

Arduino yun to parse.com

I am trying to post an object to my parse.com app from my arduino yun and it needs to post a new object every second. So far I have been able to post every 10 seconds but I cannot seem to get the arduino to post any faster than that. I tried looking into the parse library but don't see what would be slowing it down. I am using the parse library given in the guide at https://www.parse.com/docs/arduino/guide.
here is the code I have so far.
#include <Parse.h>
#include <Bridge.h>
#include <arduino.h>
ParseObjectCreate create;
void setup() {
Serial.begin(9600);
parseInit();
}
void loop() {
parseFunc(24); // just send 24 everytime for testing
}
void parseInit()
{
Bridge.begin();
while (!Serial); // wait for a serial connection
Parse.begin("**********", "***********"); //my parse keys
create.setClassName("Temperature");
}
void parseFunc(float tempC)
{
create.add("temperature", tempC);
ParseResponse response = create.send();
response.close();
}
You are probably being rate limited by Parse. The code executed in loop() is executed as quickly as the micro controller can execute it - which is very fast. As a result, you are trying to write to Parse many many more times than once a second. Try putting a call to delay() after parseFunc(24). Something like:
parseFunc(24);
delay(1000); //delay is in milliseconds
Let me know if it works!

ATtiny85 serial communication with multiple inputs

In a project, we try to set up a communication network between three ATtinys, where the first must receive messages from the other two. Those other two tinys are connected to two different pins of the first tiny. The first tiny must then receive two strings from the other tinys, one from each, and send it to an Arduino. For the communication we used SoftwareSerial. We managed to receive and send the input from one tiny, but not from both of them, because we could not find a way to read the input from only one specific pin at a time.
This is the code we used:
#include <SoftwareSerial.h>
const int rx=4;
const int rx2=1;
const int tx=3;
const int tx2=3;
SoftwareSerial mySerial(rx,tx);
SoftwareSerial mySerial2(rx2,tx2);
void setup()
{
pinMode(rx,INPUT);
pinMode(rx2,INPUT);
pinMode(tx,OUTPUT);
mySerial.begin(9600);
mySerial2.begin(9600);
}
void loop()
{
mySerial.listen();
if (mySerial.isListening()) {
mySerial.println("Port One is listening!");
mySerial.println(mySerial.read());
}
else{
mySerial.println("Port One is not listening!");
}
mySerial2.listen();
if (mySerial2.isListening()) {
mySerial2.println("Port Two is listening!");
mySerial2.println(mySerial2.read());
}
else{
mySerial2.println("Port Two is not listening!");
}
delay(500);
}
The code above worked without the part after mySerial2.listen();. Maybe the listen-function of SoftwareSerial does not work on the tinys, but if that is the case, is there another way to listen to a specific input pin?
Or do you have any advice what to do?

Resources