Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : PicoMite: gibberish by receiving data via Serial
Author | Message | ||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Hello, I am sure this is my fault, maybe one of you can help me out. I am trying to receive a simple "HELLO" String via Serial from my Arduino Uno to the PicoMite. I am sending with default settings on the Atmega328p (The default is 9600 baud, 8 data bits, no parity and one stop bit) which is also the default for MMBASIC the manual says. The send of the Arduino Uno (Atmega328p) is correct, it sends "HELLO" with no line ending what so ever. My MMBASIC program looks like this: Option explicit Option escape 'enable escape sequences (important for VFD) Dim String serialData SetPin GP1, GP0, COM1 'assign those pins for first serial port Open "COM1:9600" As #5 'open first serial port with 9600 baud Do 'serialData = Input$(4, #5) ' get up to 4 characters from the serial port Print Input$(4, #5) ' get up to 4 characters from the serial port 'Print serialData 'Pause 100 Loop I've experimented with different Pause times so on but no luck. My output is only sometimes correct: 1=! 11=! 11= !11 =!1 *ŠŠ ê *Š Šê * ŠŠ OHAL LOHA LLOH ALLO HALL OHAL LOHA I suppose, that I have to specify when it should start to recevie in MMBASIC? I am sending continuously. The setup is also correct and working, Atmega328p TX -> Level Shift -> RX (GP1 Pico) Maybe someone could point me the right direction how to use this correctly, the manual tells me how to set up parity and so on, but there is no real example... Greetings Daniel |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Untested, but in your loop try: IF LOC(#5)=>5 then Print Input$(5, #5) If you don't know how many characters will be sent, perhaps better to terminate each sending with CRLF, and read a line. ~ Edited 2023-11-02 01:47 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Hello lizby, same result as before. EDIT: I managed to solve this by adding a small Delay of 10ms on the sending device (Arduino Uno) Now it works, but why do I really need this? I suppose while (continuously!) sending, the receiver (Pico) doesn't know when to start decoding resulting in gibberish. My goal is to translate an PS/2 mouse, which is attatched to the Arduino, translate the data and send it to the pico via Serial. Since it is a mouse it NEEDS to be fast, therefore any delay would be bad... Have you any suggestions how to solve this? The whole PS/2 mouse to serial data translation works already, I just need to get the data FAST enough via Serial to the PicoMite. Greetings Daniel Edited 2023-11-02 02:08 by Amnesie |
||||
JanVolk Senior Member Joined: 28/01/2023 Location: NetherlandsPosts: 145 |
Hello Daniel Are the signal levels correct? An Arduino ATMega328P nano has a 5V output for Tx and is too high for Raspberry Pi Pico Rx input (3V3). Jan |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Hello Jan, yes as I wrote: "The setup is also correct and working, Atmega328p TX -> Level Shift -> RX (GP1 Pico)" I managed to find out that I need a small delay of 8-10ms on the transmitter side (Arduino) between every TX, because it sends continuously. But since I want to use it later on, for sending PS/2 mouse data, any delay would be bad. But I have not tested if 10ms delay would be that bad. Maybe there is a more clever approach? Edited 2023-11-02 02:19 by Amnesie |
||||
Andy-g0poy Regular Member Joined: 07/03/2023 Location: United KingdomPosts: 59 |
You need to verify the data first. Hang a scope on the Ardunio first and make sure that the output data format is correct I've seen too many issues generated by poor timing. Also choose your test data carefully remember that sending 11110000 does not generate 8 pulses the 4 "1's" and the 4 "0's" look like a single pulse. In the read loop you don't need a pause for testing just grab the input with input$ and ignore if it returns zero Andy |
||||
Andy-g0poy Regular Member Joined: 07/03/2023 Location: United KingdomPosts: 59 |
Another trap you may have fallen into. If you are receiving the data at 9600 from the Arunio AND if your console connection to the pico is at 9600 then the buffer will overflow. you have 9600 in and 9600 out with nothing left to do the processing Run the pico console as fast as possible, that may tell you a few things. Andy |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
The Pico is fast, so INPUT$(4, #5) will rarely read 4 chars. If you want 4, loop till you get them. Your PRINT outputs a new line which may well confuse you, too. Use PRINT with a semicolon (;) to suppress the new line. You won't need a delay at the arduino end (unless you put one in the Pico loop). John Edited 2023-11-02 03:09 by JohnS |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Sorry I don't understand yor post... the baud rates MUST match as far as I know. One can not set the baud rate of the Arduino to 9600 and the Pico to a higher baud rate. The buffer of the pico will "overflow" anyways, for what I expect I have to manipulate strings to get the data I want. And I already checked the serial TX signal on the scope after the level shifter. Everything is fine and my scope can decode it (and so does the serial monitor of tera term and the arduino IDE monitor) As said, things work only if I add a little bit of delay (8-10ms) on the Arduino TX side, so the Pico RX can read it. If I continuously send without delay between TX, it's only gibberish. To be perfectly clear, my Arduino code for test purpose is that simple: PICO CAN NOT DECODE ALWAYS: void setup() { Serial.begin(9600); } void loop() { Serial.print("HELLO"); } PICO CAN DECODE AT ANY TIME: void setup() { Serial.begin(9600); } void loop() { Serial.print("HELLO"); delay(10); } Edited 2023-11-02 03:43 by Amnesie |
||||
Andy-g0poy Regular Member Joined: 07/03/2023 Location: United KingdomPosts: 59 |
I am not referring to the serial data connection between the Ardunio and pico You usually have a console connection to a terminal that allows you to edit a program with the internal editor or an external one. If that link is only running at 9600 it that's the max data rate it will display. It will also have a bit of delay due to internal processing. If you PRINT INPUT$... that that print will only happen at 9600 bps, and if the data is streaming in, then the Rx buffer will fill up, eventually overflowing simply because the console cannt print fast enough. Try increasing the console speed and see if that helps. If you are not sending the data in a continuous stream then you should not have a problem. However as things improve with a small delay added in your case , this made me a bit suspicious Andy |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Hello Andy, I still don't get it Where should I set the "console speed" up if there is no console or external serial monitor program. I am only using the pico itself as a "monitor". I am sending serial data from Arduino @ 9600 baud via level shifter to the RX Pico (with VGA Monitor attached to it) and the pico PRINTs what he receives... Where or how can or should I set the "console speed" higher in the pico? Now I am 100% confused. Greetings Daniel Edited 2023-11-02 04:08 by Amnesie |
||||
Andy-g0poy Regular Member Joined: 07/03/2023 Location: United KingdomPosts: 59 |
Don't worry about it Daniel, just crossed wires You said a Pico. A pico does not have any VGA monitor connected to it. You connect to it via the USB connector on the pcb, that's the console. It looks like you are using the picomiteVGA so you don't have a serial console to worry about. I think you can safely forget what I said about the console speed :-) Andy |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6099 |
Just for the record, The pico console will always run at maximum USB speed regardless of the baud rate you set. Avoid 1200 unless you want surprises. Depending on the terminal emulator on the PC, the baud rate might have some significance. Re the mouse problem, have a look at the PS2 to serial and Wii I wrote for a nano a few years ago. The zip includes a micromite test program that may be of assistance. https://www.c-com.com.au/MMedit.htm About halfway down the page. It is usually advisable to flush the serial stream when starting so that you start at the beginning of a data packet. Jim VK7JH MMedit MMBasic Help |
||||
aFox Regular Member Joined: 28/02/2023 Location: GermanyPosts: 76 |
Hi I would try as follows: 1. LF or CRLF is a good choice. 2. Use a baudrate of 115200 between Arduino and Pico so you know, that is not the bottleneck. 3. Increase the buffer size of both devices. I think 256 bytes is to small for a continuos data stream. 4. Throw some of the mouse data within the Arduino away. Maybe every second data record. Gregor |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Jim! After spending the whole day with my nooby kind of MMBASIC "skills" I almost gave up and tried your program (seems it was written for the CMM2). First there were a bunch of errors since I am using a PICO not CMM2, so I deleted everything what throws an error on me and I had to set the pins for COM1. Uploaded your code for the Arduino Nano to the Arduino UNO and bingo. This works just perfect! Wow! Since I only deleted (kind of randomly) "wii" based code on your original program, I now have to figure out how your code works and what wii-based stuff I can further delete to clean up this program a bit for better udnerstanding. But long story short. Can't thank you enough for this! With a PS/2 Mouse on the Pico (via Arduino + Level Shift) there are SO MANY cool things I can try EDIT: And I am suprised how fast the mouse reacts! Everythings works well, XYZ wheel and buttons. Just wow! Greetings Daniel Edited 2023-11-02 07:27 by Amnesie |
||||
Print this page |