I am using an Arduino Leonardo and the DFrobot RS232 shield to try and communicate with a flux meter. I am trying to write "UNITS?", which would have the fluxmeter send back a single byte that would translate to which units it is using.
The problem is, I can see from the Arduino side it is writing those 6 bytes, but at the if (Serial1.available()), there is nothing there. I have the switch on the shield to on, and I did the tutorial on the DFrobot wiki to make sure my shield works.
I think it has to do with how the Serial1.write() is done. I don't think it is receiving the command correctly, so it does not respond.
Shown below is my code:
#include <Keyboard.h> // Define pins, so you only need to change them in one spot #define BUTTON 7 bool runner = 0; void setup() { // Begin Serial communication at 9600 baud rate Serial1.begin(9600); pinMode(BUTTON, INPUT); // create an interrupt that will call send_command() whenever the button pin has a rising edge attachInterrupt(digitalPinToInterrupt(BUTTON), send_command, RISING); // start the Keyboard process Keyboard.begin(); } // called when button is clicked // will use Serial.write() to send commands // then will write the data with the keyboard void send_command() { runner = 1; return; } void loop() { if (runner) { char pkneg, pkpos; // This next section writes the commands to the 480, // then reads the data and prints it to the Serial Monitor int sent = Serial1.write("UNITS?"); Keyboard.println(sent); if (sent <= 0) { Keyboard.print("Fort Myers we got a problem\n"); } //Keyboard.print(marker); delay(5000); if (Serial1.available()) { Keyboard.print("Here!\n"); pkpos = Serial1.read(); } else pkpos = 'x'; pkneg = 'x'; char pkneg1[10], pkpos1[10]; // dtostrf(pkpos, 4, 3, pkpos1); // dtostrf(pkneg, 4, 3, pkneg1); Keyboard.print(pkneg); Keyboard.print('\t'); Keyboard.print(pkpos); Keyboard.print('\n'); // for testing runner =0; } }