I have recently started using the 18v15 simple motor controller again and am trying to read the temperature from a Raspberry Pi 3 using the Get Variable Command. For some reason, I seem to be receiving only 1 byte of data though the datasheet suggests I should receive 2. Attached is a photo from my code which I suspect to be the issue. I have tried delaying the TTL response, waiting between writing and reading to the controller, changing baud rate, etc. Any help would be greatly appreciated as I’m quite new to all this.
18v15 Simple Motor Controller-> TTL Delayed Response, Fixed Baudrate 9600.
Raspberry Pi 3 - > Serial Setup using wiringPi. Read/Write using unistd.h library. GPIO TTL Serial Tx & Rx Pins. C++ compiled on Pi using g++.
I did not notice anything wrong with your snippet of code. Does the red error LED on the Simple Motor Controller turn on after sending the Get Variables command?
It’s possible your Raspberry Pi is configured to return bytes as soon as they are available. You could try doing two separate read commands, each reading one byte, to see if that’s the case.
By the way, for those following this thread, please note there is a known issue with the Raspberry Pi 3’s UART interface, which it seems you resolved from this post.
Thanks for responding and helping out with possible solutions. I had the same thought about using 2 read() functions before making the post with no luck. I recreated and executed it for reference in attachments.
On the terminal output, you can see I compiled and then executed a few times, giving 5-7 seconds between each one. After the 3rd exec (where you can see I tapped the arrow keys " ^[[A^[[B ") the program stalled and did not immediately grab serial data as before. Looking at the control center on my windows device, I started receiving serial format errors and the red error light came on. Even before it , however, where it says 2 bytes have been read (1 per read()), I seem to be getting garbage values as the controller is currently in room temperature and was not on more than 5 minutes before executing this code.
As a side note, I am using the compact protocol because if I use the Pololu protocol I immediately get serial format errors. The device number is 0x01 and I was sending the command [0xAA, 0x01, 0x21, 0x18]
Just to be clear, writing to the controller is working absolutely fine with 0 issues. It is only reading where I am having issues.
Any help is greatly appreciated!
Have you ever been able to successfully read from your SMC? Can you post pictures of your setup showing how everything is connected?
From your output, it looks like the first two tests were successful; the SMC temperature reads 24.0 degrees C for the first test and 24.1 degrees C for the second if you use the first byte read from the first and second readings in each test.