|
Post by glennl on Apr 22, 2024 12:59:52 GMT
Hiya.
I have a microcontroller sending a stream of data out a serial port every second, typically something like [<LAT>100.00000</LAT><LNG>50</LNG><COM>18</COM>]. I'm using a Serial-USB adapter, and I can confirm the data is coming in using a terminal program on the same computer, but my JUSTBasic test code just wont pick it up. Have checked the baud rate. No errors, just a repeating "Nothing yet." Am I missing something in my code? Its on Windows 10, JUSTBasic ver 2.0
open "COM3:57600,n,8,1,ds0,cs0,rs" for random as #comm
SerialData$="" Timer 500, [RunQue]
[RunQue]
SerialData$ = SerialData$ + input$(#comm, lof(#comm))
if len(SerialData$)>1 then
print "We have data."
else
print "Nothing yet."
end if
wait
Thanks Glenn
|
|
|
Post by xxgeek on Apr 22, 2024 15:52:15 GMT
Don't know much about comm ports Glen, but there may be an issue with your timer.
Does the following code keep printing "Nothing yet." too?
open "COM3:57600,n,8,1,ds0,cs0,rs" for random as #com SerialData$="" do scan Timer 500, [RunQue] wait [RunQue] timer 0 count = txcount(#com) print count SerialData$ = SerialData$ + input$(#comm, lof(#com)) if len(SerialData$)>1 then print "We have data." else print "Nothing yet." end if loop until theCowsComeHome wait
|
|
|
Post by Rod on Apr 22, 2024 18:07:40 GMT
If you are sure about the com port number and the baud rate then it is most likely DTR that is your issue. What specific device are you connecting and does i5 have a web support page. For example does it need prompted to start transmission. There are threads discussing GPS dongles and their transmissions. Ultimately you will need to browse and understand the issues covered here alycesrestaurant.com/lbpe/AccessingSerialPort.htmlThe txcount () is counting characters waiting to be sent, so not relevant to your incoming data. I think your timer code would work ok , it would check immediately then every 500ms.
|
|
|
Post by Rod on Apr 22, 2024 18:27:50 GMT
Check what com port is getting used with this code.
nomainwin 'We need an array to store the Com port names in dim port$(256) 'since we plan to use Subs we need a few globals 'I tend to identify global variables with a capital letter global Port Port=0
WindowWidth = 550 WindowHeight = 195 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) combobox #main.cbport, port$(, portClick, 5, 80, 50, 100 statictext #main.stport, "Com Port", 5, 60, 60, 20
open "Arduino simple interface" for window as #main #main "trapclose quit"
'find out what com ports are available and load the combobox call getPorts
'we need an endless loop to clear out the serial buffer while 1 scan 'call getresponse wend
'Subs to handle the com port ============================================== sub portClick h$ 'take com port combobox input, open choosen com port #main.cbport "selection? p$" if Port then close #port if p$<>"" then open p$;":9600,n,8,1,ds0,cs0,rs" for random as #port Port=1 call delay 500 end if end sub
sub getPorts 'test first 32 ports and load combobox list for valid serial ports index=1 for p = 1 to 32 oncomerror [trap] open "Com";str$(p);":9600,n,8,1,ds0,cs0,rs" for random as #com port$(index)="Com";str$(p) index=index+1 close #com
[trap] oncomerror next #main.cbport, "reload" 'now if there is only one port open it if port$(1)<>"" and port$(2)="" then open port$(1);":9600,n,8,1,ds0,cs0,rs" for random as #port Port=1 #main.cbport, "selectindex 1" call delay 500 else #main.cbport, "selectindex 0" end if end sub
sub delay m timer m, [done] wait [done] timer 0 'CallDLL #kernel32, "Sleep", m As ulong, Sleep As void end sub
sub quit h$ close #main if Port then close #port end end sub
|
|
|
Post by glennl on Apr 22, 2024 22:48:24 GMT
Thanks, that code correctly detected com 3. I'm using a ESP01 for testing, it has a programming board that handles the serial to USB. The code on the ESP sends a string of data every second. As mentioned if I fire up a serial terminal ( Tera Term ), and set the port to com 3, 57600 baud, I see the data streaming down every second, no errors. The JUSTBasic code correctly finds com3, but its as though there is nothing coming in, but I know there is. I've tried another port, same. Is 57600 to fast for JUSTBasic?
I'll test the code on another PC, and try changing it to 9600. Thanks for the link to AccessingSerialPort, good info.
Glenn
|
|
|
Post by glennl on Apr 22, 2024 23:27:13 GMT
OK, tried 9600, and tried another PC ( also win10 ), same result, no data. However Tera Term on both sees the data streaming in.
Silly question, but has anyone confirmed JUSTBasic can access the serial ports under Windows 10?
I ask because I used JUSTBasic to access the serial port back in Windows XP days, and fired up the same code I used back then, and it also no longer works.
Glenn
|
|
|
Post by glennl on Apr 23, 2024 0:18:28 GMT
OK, further testing and I'm seeing a lot of "isEMpty is not recognised" errors. This is my code
open "COM3:9600,n,8,1,ds0,cs0,rs" for random as #comm
Timer 500, [RunQue]
[RunQue]
' Grab a chunk of data from the serial buffer SerialData$ = input$(#comm, lof(#comm)) if len(SerialData$)>0 then print "Data" else print "Nothing yet." end if wait
So those isEmpty errors are in the JUSTBasic code itself. I can only assume the serial processing code in JUSTBasic is broken in Windows 10. Wish I knew that a week ago before I started this project.
|
|
|
Post by Rod on Apr 23, 2024 6:27:47 GMT
Ok, NO. Liberty and just basic can handle all serial input on WinX to Win11
The issue is DTR. Your device must be set to use that handshaking line. You can probably set the device to not need it, fudge the wiring to set it high, or use the API examples in the LBPE article.
Keep us up to date on how you get on. There are also other threads that mentioned device, will try to search those out.
|
|
|
Post by Rod on Apr 23, 2024 10:31:27 GMT
Having read a bit more I assume you have a gps device connected to the esp01 device and the esp01 connected to the pc via usb serial connector.
Given it all works with other software on the same pc then the issue is DTR
DTR is usually connected to GP100 on the esp01 this signals a firmware update. So the esp01 can start normally or await an update.
If you have access to the wiring and can change DTR then clamp it low or high with a pull up or pull down resistor and test. Or simply disconnect it, but that leaves it floating and it may cause errors.
You don’t actually need any of the handshaking lines. A three wire connection should suffice. Tx Rx and Grd
When I get time I may order a device and test it out myself. The question has been asked in the past.
|
|
|
Post by Rod on Apr 23, 2024 11:41:55 GMT
GPIO0, GPIO2 and GPIO15 pins
These pins determine what mode the chip starts up in.
For normal program execution GPIO0 and GPIO2 need to be pulled up to Vcc (3.3V) and GPIO15 needs to be pulled to GND, each with a resistor in the range 2K to 10K resistor. A 2K resistor gives better noise immunity. OLIMEX uses 2K resistors SparkFun uses 10K resistors. I use 3K3
If you can’t get to these wires can we get the specifics of the devices used and how they are connected?
|
|
|
Post by tenochtitlanuk on Apr 23, 2024 12:52:14 GMT
I have an ADC that presents as a serial port via USB, and the following code works happily for me on W10. May help as an example..??
open "com34:115200,n,7,1" for random as #fIn
CRLF2$ =chr$( 13) +chr$( 10) +chr$( 13) +chr$( 10)
I$ =input$( #fIn, lof( #fIn)) ' discard anything in buffer
timer 1000, [o]
wait
[o] print "Checking ADC", cnt =0
do i$ =input$( #fIn, 1) ' read single byte. if i$ =chr$( 13) or i$ =chr$( 10) then cnt =cnt +1 else cnt =0 loop until cnt =4 ' we've met the frame separator...
I$ ="" do i$ =input$( #fIn, lof( #fIn)) I$ =I$ +i$ loop until len( I$) >=10 *17 ' pick up the whole frame.
'print I$ ' print all ten channels every second OR a selected one. print time$(), "ADC count = "; mid$( I$, 17 *5 +5, 4); " representing "; mid$( I$, 17 *5 +10, 6)
wait
|
|
|
Post by glennl on Apr 27, 2024 5:38:22 GMT
I worked out its the standard serial-usb adapter that's used with the ESP's. I tested bot a ESP6266 dev board with its own serial-usb port, and the ESP01 that uses a daughterboard to give the USB connection. These are used to program the ESP's, and send serial data back and forth to a PC. These work fine for the ESP programming software ( Arduino IDE ), and serial terminal programs like Tera Term. But not with JUSTBasic.
The fix, in my case, was to bypass the daughter board on the ESP01, or onboard serial-USB on the ESP8266, and connect a off the shelf USB to serial adapter to the Tx and Rx pins of the ESP. That worked.
Thanks for the input.
Glenn
|
|
|
Post by Rod on Apr 29, 2024 12:14:58 GMT
I purchased an esp-01s board and its usb uart. Initially I had no luck connecting via the serial port. Until I downloaded updated serial drivers from the manufacturers site AI-THINKER. After that it connected without problems. To be a bit clearer, the usb uart worked right away. I connected the Tx and Rx and I could send and recieve without issue but it would not communicate with the esp-01s board. The updated drivers fixed the issue for me. This program sent and received the AT and ATOK messages, use the debugger to step through and give time for the port to open and the messages be sent and received. Use the single step icon to step through each line of code.
open "Com5:115200,n,8,1,ds0,cs0,rs" for random as #com
#com "AT"
[checkport] print lof(#com)
i$=input$(#com,lof(#com)) print i$
close #com
end
|
|