Serial communication using Arduino and RS 232 cable - arduino

I am trying to control KEITHLEY Electrometer 6517B using Arduino by sending the SCPI commands but I am not getting any input. I bought an RS232 converter and using the TX and RX pins. Below is the code that I'm using.
void setup() {
Serial.begin(19200);
Serial1.begin(19200); // port that RS232 is connected to
}
void loop() {
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
if (Serial.available()) {
char ser = Serial.read();
Serial1.write(ser);
}
}
I did the following with Python but it was working there but not here.

Related

How to get via Arduino the RSSI of an Xbee3.0 in transmission in API mode with another Xbee3.0?

Prelude: I am harmful in arduino.
My objective so far is to retrieve the RSSI (Received Signal Strength Indication) of an Xbee3.0 (denoted Xb1 thereafter and in API mode) connected to an Arduino Mega. The latter is connected to the computer by cable. Xb1 receives a signal from another Xbee3.0 (denoted Xb2 - also in API mode). Xb2 is connected directly to the computer and sends information via XCTU.
From what I see, Xb1 is receiving information from Xb2. The problem is that I can't display on Arduino the RSSI of the Xb1.
Xb1 is connected via PWM 10 of the arduino mega and via Tx and Rx (and is of course powered and grounded).
I tried several codes, including this one:
#include <XBee.h>
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 8 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 9 (Arduino's Software TX)
SoftwareSerial serial1(8, 9); // RX, TX
XBee xbee=XBee();
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();
uint8_t option = 0;
uint8_t data = 0;
uint8_t rssi = 0;
void setup()
{
Serial.begin(9600);
serial1.begin(9600);
xbee.setSerial(serial1);
}
void loop()
{
xbee.readPacket(100);
if (xbee.getResponse().isAvailable())
{
Serial.println("available");
if(xbee.getResponse().getApiId() == RX_64_RESPONSE || xbee.getResponse().getApiId() == RX_16_RESPONSE)
{
Serial.println("16");
if (xbee.getResponse().getApiId() == RX_16_RESPONSE)
{
Serial.println("16");
xbee.getResponse().getRx16Response(rx16);
//option = rx16.getOption();
//data = rx16.getData(0);
int rssi = rx16.getRssi();
Serial.print("data: ");Serial.println(data);
Serial.print("option: ");Serial.println(option);
Serial.print("RSSI: ");
Serial.println(rssi);
}
else
{
Serial.println("64");
xbee.getResponse().getRx64Response(rx64);
//option = rx64.getOption();
//data = rx64.getData(0);
int rssi = rx64.getRssi();
Serial.print("RSSI: ");
Serial.println(rssi);
}
}
}
}
....which unfortunately did not give me satisfaction. The conditions would obviously not be verified.
Do you have any idea why this is not working?
Thanks in advance,
Cordially

XBee-Pro 900HP Communication in API Mode

I've been been trying to get an Xbee-Pro 900HP to communicate with another Xbee, but it doesn't seem to work. I've confirmed that the xbees are set up correctly as they can communicate remotely over XCTU, so it is either my code or my setup. I've gotten the setup checked by people I trust, so that really only leaves the code. Do you have any idea what I'm doing wrong? (Teensy 4.0, API 2 Mode)
#include <Printers.h>
#include <XBee.h>
//int test1 = 5;
XBee xbee = XBee();
//SoftwareSerial sserial(1,0);
//String altstring = String(alt);
uint8_t test1[]= {'H', 'i'};
//Tx16Request tx = Tx16Request(0xFFFE, packet, sizeof(packet));
void setup() {
Serial.begin(9600); //debug
Serial1.begin(9600);
Serial2.begin(9600);
xbee.setSerial(Serial1);
delay(1000);
Serial.println("Setup Complete\n");
Serial.println("Check Reciving radio Console");
}
void loop() {
Serial.println("test");
XBeeAddress64 addr64 = XBeeAddress64(0x13A200, 0x41DDEE70);
Tx64Request tx = Tx64Request(addr64, test1, sizeof(test1));
xbee.send(tx);
delay(5000);
}

How to send orders from Arduino to Esp32 and make it keypress

I need to send orders from Arduino to ESP32.
I have one joystick button to test.
Arduino nano is sender
Esp32 is receiver
Esp32 receives the joystick button information from Arduino (each time I push the button).
I need the Esp32 to Serial.write according to the data, for example:
If I press the button in Arduino: Send the data to Esp32 and turn bluetooth on (or turn a led on).
These are my codes:
//Arduino NANO sender
byte j = 45;
#define boton_joystick A1
void setup() {
Serial.begin(9600);
pinMode(boton_joystick, INPUT_PULLUP);
}
int boton_joystick_state;
void loop() {
//Serial.println("100");
//Serial.write("BOTON EN GRANDE");
//delay(1500);
if(!digitalRead(boton_joystick)) {
boton_joystick_state = 1;
delay(170);
} else {
boton_joystick_state = 0;
}
if (boton_joystick_state) {
Serial.println(j);
Serial.print(" ");
Serial.write(j);
Serial.println();
}
//ESP-32 receiver
#define RXD2 16
#define TXD2 17
byte j = 45;
int comdata;
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}
void loop() {
//Serial.print("LEYENDO ARDUINO");
Serial.println(Serial2.readString());
if (Serial2.available() >0) {
char comdata = char(Serial2.read());
if (comdata == 'j') {
Serial.println("joystick activado");
}
}
}
am not sure
but am using Nano 33 BLE with UART and Nano has also Serial1 no need to serial2 no need to Softwearserial. Sensd on serial 1 and recive in Serial 1 but also you have to connect it Via USB. so your serial is USB and your serial 1 is TX RX.
for me it work so you can try it.

Serial software is not able to write and read the data

I am trying to write a data to the software serial port. But I am not able to read the data.
I have used the following code:
#include<SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
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(57600);
mySerial.println("Hello, world!");
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
Please can anyone of you help me. Thanks in advance

Unable to do Arduino Mega to Arduino Mega serial communication

Based on the circuit below, I tried hooking up two Arduino Mega for serial communication.
The code for sender:
char mystr[3] = "Hello"; //String data
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
Serial.write(mystr, 5); //Write the serial data
delay(1000);
}
The code for receiver:
char mystr[5]; //Initialized variable to store received data
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
Serial.readBytes(mystr, 5); //Read the serial data and store in var
delay(1000);
}
There is no output in the Serial console of Arduino. Could someone please inform me of the possible cause and solution for the same. If I've missed out anything, over- or under-emphasized a specific point let me know in the comments.
If I understood this right you have one Arduino connected to your pc and to another Arduino?
The problem is that you need to specify which Serial port to use:
That is rather easy, just type Serial1 or Serial2 instead of just Serial. That allows you to open 2 Serial ports: One to your other Arduino and one to your Computer for Displaying the results !
LINK: https://www.arduino.cc/en/Tutorial/MultiSerialMega
You need to check available data from serial:
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
Serial.readBytes(mystr, 5);
Serial.print("I received: ");
Serial.println(mystr, DEC);
}
}

Resources