I'm working on a simple program which should communicate with a Casio CFX-type graphical calculator (the cfx 9850, in my case) over serial. The CFX (and Prizm) calculators support serial communications from programs, using send( and receive( commands over a 2.5" stereo (3-pin) jack, where tip is send and ring is receive. If I hook it up through a FT232 adaptor (VMA440), I can read/see the data transmit from the calculator using a terminal software. It's set to "9600 bps, 8N1, no handshake" and the first byte I read is 0x15.:
[15]"[15]"
Documentation found online details the handshake protocol the Casio uses, and it should indeed begin with a 0x15 which should be acknowledged by returning a 0x13. So my idea is to make a simple program which waits for serial data, and writes a 0x13. Currently, I'm using an ESP-01, hooked up as per the diagram. However, I just can't seem to read that 0x15 byte -- I keep getting something else. Since I can read correctly using a "direct connection" to a terminal software, I expect the problem must be in my Arduino code.
Ready @ 9600
Read data
"
00100010
Received something else
... and I never seem to reach the second read, after replying with the 0x13. Here is my little test sketch:
void setup() {
Serial.begin(9600, SERIAL_8N1); // Initialize serial communication
Serial.println("\nReady @ 9600");
}
void printByteBits(byte b) {
for (int i = 7; i >= 0; i--) { // Iterate from bit 7 to bit 0
Serial.print((b >> i) & 1); // Shift right and mask with 1 to get the bit value
}
Serial.println(); // Move to the next line after printing all bits
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available()) {
char receivedChar = Serial.read();
Serial.println("Read data");
Serial.println(receivedChar);
printByteBits(receivedChar);
if (receivedChar == 0x15) {
Serial.println("Received hello");
} else {
Serial.println("Received something else");
}
Serial.write(0x13);
while (Serial.available()) {
char receivedChar2 = Serial.read();
Serial.println("Read 2 data");
Serial.println(receivedChar2);
printByteBits(receivedChar2);
}
}
}
Maybe your calculator doesn't like all the serial.prints that you are sending to it?
Did you try softwareserial?
Are your calculators serial line voltages matching 3V3?
Sorry for the perhaps messy drawing... First time using Fritzing. Couldn't find an ESP-01 model, so I had to use an 8266 Huzzah. But it should be much the same.
I tried removing the serial prints -- particularily the ones before the 0x15, to see if I could reach the second byte from the calculator but no luck. The calculator does work with the FTDI RS232 adapter directly, and it is configured to 3V (not 5V), so I'm sort of assuming 3.3V TTL ought to work.
I have not tried software serial though. Maybe I should use a bigger breakout (8266 Huzzah, or an ESP32) with more pins, so I could use the hardware serial to debug (i.e. print to the computer to see what's going on) and use a separate software serial for interfacing with the calculator.
I suggest you to Use Esp32 or another board that has more than one hardware serial, softwareserial is not so reliable and is mainly used with boards that has only one HW serial. Like yours. I don't remember any more, if esp-01 have pins available for SW serial.
Sorry -- again, this is due to me being new to Fritzing... I'm powering the board from a "breadboard USB power adapter", which gives 3.3V. Should really have pointed this out; guess I was too quick to post. I'll update the post!
Thanks for the tip on the ESP32 having multiple hardware serials -- I'll look into that. I was hoping to find some small project for using my bag of ESP-01, but they do tend to be too limited for almost any project.
So... the problem -- yet again -- was the breadboard. Can not run anything on a breadboard which involves data transfer. The breadboard will mess it up, guaranteed. I moved everything off the board, and connected with a mess of Dupont cables, and now I am able to read a 0x15 and reply with a 0x13. Thanks for the input though, and sorry for blaming the ESP-1