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 : Help, I'm too stupid to connect two Picomite via RX/TX
Page 1 of 2 | |||||
Author | Message | ||||
Gerad Regular Member Joined: 10/01/2024 Location: GermanyPosts: 42 |
Help, I'm too stupid to connect two Picomite (Webmite) via RX/TX. Pico No.1 should provide a few bytes, which picks up Pico No. 2 once a day Who can send me a few lines of programming to learn? Please provide a few simple explanations. My basic knowledge comes from the ZX-81 era. Unfortunately there isn't much left. I am an absolute beginner. Gerad |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6785 |
Your first step is to read Appendix A (Serial Communications) of the Webmite manual. Sorry, you can't avoid this. :) You will have two Webmites, so let's call them A and B. A will be the "master", responsible for asking for data. B will be the "slave", which returns the data when asked for it. WARNING - I haven't tested the following. I think you might have to send carriage return and line feed characters. No doubt someone will correct me. :) Lets say you are using pins GP0 (Com 1 TX) and GP1 (Com 1 RX) on device A and GP4 (Com 2 TX) and GP5 (Com 2 RX) on device B. Link device A GP0 to device B GP5 Link device A GP1 to device B GP4 As I said previously, I prefer to use 220R resistors rather than direct connections, but that's me. :) Code for device A - "master" SETPIN GP1, GP0, COM1 OPEN "COM1:4800" AS #1 'the program loop 'every second it sends "X" then waits for a second. 'then it reads the received 6 characters into a$ and prints them. do print#1,"X" pause 1000 a$=input$(6, #1) print a$ pause 1000 loop Code for deice B - "slave" SETPIN GP5, GP4, COM2 OPEN "COM2:4800" AS #2 'the program loop 'this keeps looking for a character in the receive buffer 'if there is a character there then it sends "Gotcha" as a reply do a$ = input$(#1) if a$ > "" then print#1,"Gotcha" endif loop loop Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
Extra loop there, Mick do a$ = input$(#1) if a$ > "" then print#1,"Gotcha" endif loop loop Also gonna get some phantom "Gotcha"s due to CR & LF |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4226 |
A very simple terminal program, uses above techniques. Run on both mites, connect RX to TX between mites. 'terminal program for PicoMite 'open port SetPin gp1,gp0,com1 Open "COM1:9600,,rec_int" As #1 'transmit loop Do Do a$=Inkey$ Loop While a$="" Print #1,a$; Loop 'receive Sub rec_int b$=Input$(10,#1) 'max 10 characters at once Print b$; End Sub Volhout PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6785 |
Oops - well, I am a bit loopy. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 368 |
I'm not a hardware guy at all, so feel free to point and laugh at my ignorance but if he's running off separate power sources, should he also connect the Ground pins together? Edited 2024-04-26 01:36 by PeteCotton |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6785 |
I must admit that I'd assumed that.... :) Sometimes it's easy to miss the obvious. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Gerad Regular Member Joined: 10/01/2024 Location: GermanyPosts: 42 |
Hi Mick The slave code generates the following error message [4] a$ = Input$(#1) Error : Syntax Gerad |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6785 |
Sorry. I think it should be a$=input$(1,#1) because you are expecting a single character. Manual page 137: INPUT$(nbr, [#]fnbr) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Gerad Regular Member Joined: 10/01/2024 Location: GermanyPosts: 42 |
Mick, I thought so too. But now comes this message [4] a$ = Input$(1,#1) Error : File number is not open gerad |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Is it open? We probably need more of your code. What exactly is it you're trying to send? ~ Edited 2024-04-26 04:00 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6785 |
Spot the mistake. :) We OPENed the file as #2. Now we need input$(1,#2) to read from that port. We will also need PRINT#2 to transmit through it. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Gerad Regular Member Joined: 10/01/2024 Location: GermanyPosts: 42 |
Mick, Great, it works. However, only every 7 transmission is complete Gotcha Gotc ha Goa tchaI Gotcha Gotc ha Go tcha Gerad |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
If you really want to send (and receive) more than one character at a time, you would probably do best to send a message terminated with carriage return and line feed (CHR$13 and CHR$10) and read the entire message with LINE INPUT #2,a$--and break out the fields (if any) with FIELD$. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
PeteCotton Guru Joined: 13/08/2020 Location: CanadaPosts: 368 |
Can you post the code you are using please? Then we can have a proper look at what's happening. Cheers, Pete |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9306 |
Agreed. You then let the internal COM port buffers take care of holding on to the data, till you are ready to read it out into a string or whatever. You can transmit your data from "A" at any point, and module "B" will buffer the messages and you can simply read them inside a loop: Open "COM2:9600" as #2 'Open the COM port DIM MSG$ 'String to hold any one message DO 'MAIN LOOP HERE MSG$="" 'Clear the global message string ... If LOC(#2) then RXD 'Something has arrived in the serial port buffer If MSG$<>"" then Print MSG$ 'Show the message on the terminal screen if there is one to show ... LOOP SUB RXD Pause 100 'Allow all of message to arrive in buffer Local T$ 'String for use ONLY inside this sub Do 'Suck message from COM port buffer: T$=INPUT$(1,#2) 'Suck a byte from the buffer If T$=Chr$(13) Then Exit Do 'If it is a CR byte, hop out of this loop MSG$=MSG$+T$ 'Otherwise, add the byte to the MSG$ string Loop 'Do it all again, till a CR byte IS found... END SUB This is a very cut-down simple serial processor. Each message that "A" sends to "B" must have an end-of-message marker(EOMM). I've used CR in my example, but I have also used CHR$(27) - Escape. Your EOMM can be any byte you like, so long as it is NEVER used as part of the message itself. You have around 127 non-printable characters you could potentially choose from. The beauty of building the message from the buffer a byte at a time like this, is that the main loop will process messages one at a time, meaning you can have several different messages waiting in the buffer, and the main loop will process them out one at a time, turning the COM port buffer into a lovely automatic message queuing system so you never lose a message, if the main loop is doing something else, when module "A" happens to send data to module "B" - the serial port buffer will save the data in the background for you if the main loop is busy, in other words. The example code above, does not allow for checksum or corrupted messages - you need to deal with that in your main code, by analyzing MSG$ to make sure it is a valid message - my example does not do that, cos we're just trying to get you up and running with a simple example first. Edited 2024-04-26 10:56 by Grogster Smoke makes things work. When the smoke gets out, it stops! |
||||
Gerad Regular Member Joined: 10/01/2024 Location: GermanyPosts: 42 |
Hello Pete I'm using the code that Mick (Mixtel90) kindly sent me to understand how the serial transfer works. It took me a little further. But I don't understand why only every 7th transfer is correct. After that I try to install and understand the Volhaut, Lizby and Grogster examples. Lizby said "If you really want to send (and receive) more than one character at a time, you would probably do best to send a message terminated with carriage return and line feed (CHR$13 and CHR$10) and read the entire message with LINE INPUT #2,a$--and break out the fields (if any) with FIELD$." How do I do that ? I have much to learn. The Code from Mick: Code for device A - "master" SETPIN GP1, GP0, COM1 OPEN "COM1:4800" AS #1 'the program loop 'every second it sends "X" then waits for a second. 'then it reads the received 6 characters into a$ and prints them. do print#1,"X" pause 1000 a$=input$(6, #1) print a$ pause 1000 loop Code for device B - "slave" SETPIN GP5, GP4, COM2 OPEN "COM2:4800" AS #2 'the program loop 'this keeps looking for a character in the receive buffer 'if there is a character there then it sends "Gotcha" as a reply do a$ = input$(1,#2) if a$ > "" then print#2,"Gotcha" endif loop Regards Gerad |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3801 |
You have something that works enough to show some ideas. Unless you really want to use FIELD$ - don't. It's a complication which from your original post you don't need. Let's go back to what you want to send - give us details. You're in danger of writing code (and e.g. using FIELD$) without enough of a spec. John |
||||
Gerad Regular Member Joined: 10/01/2024 Location: GermanyPosts: 42 |
Hi John My system consists of 3 Webmite. Since I only have 4 CIN pins available but need 12, the remaining two webmite should have their CIN values (waterflow) transferred to the master via serial transmission. I thought serial transfer was the easiest way for a few bytes. Gerad |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3801 |
It does sound easy and it can be - you have it mostly working now. If you have n different things to send you might want to send each with (say) a starting letter, then the value, then either a CR or LF (whichever MMBasic likes to treat as line terminator when doing LINE INPUT). For n <= 26 you could put a letter of the alphabet. Let's imagine you've read CIN 1 into a variable called value1, you might use PRINT #1, "A";value1;EOL; where EOL is the CR or LF and with the COM port open on #1 - and note all the semi-colons as you don't really want anything more sent. On the other mite you'd used LINE INPUT #1, A$ and LEFT$(A$,1) will be "A" MID$(A$,2) will be value1 - as a string, its value would be VAL(MID$(A$, 2)) John Edited 2024-04-26 22:50 by JohnS |
||||
Page 1 of 2 |
Print this page |