Serial comms on picomite


Author Message
Gbbickerton
Newbie

Joined: 22/06/2022
Location: United Kingdom
Posts: 11
Posted: 02:57pm 02 Feb 2024      

I cannot get serial comms to work on the picomite, the picomite is set up on a pico res touch from waveshare, I am sending serial data from a small picaxe board that sends text at 1200 baud this is working because I can receive the text via a ttl to usb converter on the MM edit terminal, I am using this code.
Currently the picomite is in a breadboard for trouble shooting.


do
SETPIN GP5, GP4, COM2 '
OPEN "COM2:1200" AS #5 '
dat$ = INPUT$(1, #5) '
print "data"
print dat$
print loc(#5)
CLOSE #5 ' close the serial port
pause 100
loop


loc(#5) returns 0, so no data in the buffer.

Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3696
Posted: 03:04pm 02 Feb 2024      

Hi Gbbickterton,'

When you open a serial port, it starts with a clean RX and TX buffer.
You program
Do
opens the serial port
Then it checks for data
Then closes it
Then waits 100ms
loop

There is very little chance a valid character is received in the microseconds.
I think your program should

open the port.

Do
check content of buffers
pause
Loop

close the port


Volhout
Edited 2024-02-03 01:07 by Volhout

Gbbickerton
Newbie

Joined: 22/06/2022
Location: United Kingdom
Posts: 11
Posted: 03:49pm 02 Feb 2024      

That sorted it, thank you

lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3036
Posted: 04:01pm 02 Feb 2024      

Welcome to the forum.

MMBasic has excellent serial communications handling. Depending on circumstances, you'd probably do best with something like this (untested):

SETPIN GP5, GP4, COM2 '
OPEN "COM2:1200" AS #5 '

do
 Do
   'HERE you want to put any code which is needed between receipt of characters, e.g.,
   if dat$ <> "" then
'     your code
     dat$=""
   endif
 Loop While Loc(#1)=0
 Pause 100 ' let characters arrive on COM1 (approx 10 per 100ms--increase as needed)
 dat$ = INPUT$(255, #5) 'get up to 255 characters
loop

JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3683
Posted: 05:37pm 02 Feb 2024      

The LOC(#1) should be LOC(#5), didn't spot anything else - but untested.

John

lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3036
Posted: 06:46pm 02 Feb 2024      

  JohnS said  The LOC(#1) should be LOC(#5), didn't spot anything else - but untested.


Thanks--cut and paste error (plus lack of proofreading).

Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9137
Posted: 10:17pm 03 Feb 2024      

The COM port buffers are a thing of beauty, and I use them often as a fully automatic message queue, which can receive messages in the background, and your code just has to check the buffer as part of the main loop, and act if there is anything there to process.  They are BEAUTIFUL to have.

Gbbickerton
Newbie

Joined: 22/06/2022
Location: United Kingdom
Posts: 11
Posted: 06:03pm 09 Feb 2024      

Thanks for the help, my project is a DIY turbo trainer it uses a home made axial flux generator driving 2 mini moto electric motor bike motors with fans. A picaxe reads the current and voltage and sends the data via 433mhz units to a picomite with waveshare display. The data is in the form of UUUUUUUUUUYSM preamble these letters have equal mark space ratio which sets up the bit slicer, when YSM is  detected the next 6 bytes are the voltage current and checksum.

lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3036
Posted: 07:49pm 09 Feb 2024      

Thanks for the explanation and the photo. Looks like heavy metal (at least for a picaxe). How are you determining the current?

"Turbo trainer"--sorry for my ignorance, but trainer for what, if you don't mind?

Gbbickerton
Newbie

Joined: 22/06/2022
Location: United Kingdom
Posts: 11
Posted: 05:40pm 19 Apr 2024      

A turbo trainer is for putting your bike on to provide resistance to pedal against while going nowhere, useful in the winter when its a bit chilly outside.
The generator and motors provide a really nice feeling load.
The two white blocks are wire wound resistors the voltage across is measured to get the current, the losses are taken into account when calculating the wattage output by the rider.

lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3036
Posted: 07:21pm 19 Apr 2024      

Ok, thanks.

PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 368
Posted: 12:44am 20 Apr 2024      

  Gbbickerton said  A turbo trainer is for putting your bike on to provide resistance to pedal against while going nowhere, useful in the winter when its a bit chilly outside.
The generator and motors provide a really nice feeling load.
The two white blocks are wire wound resistors the voltage across is measured to get the current, the losses are taken into account when calculating the wattage output by the rider.


Business Op. Have them tied in to the grid. Also have convicts and climate-alarmists pedal them  

Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5847
Posted: 07:26am 20 Apr 2024      

Surely the next step is to feed an inverter/regulator and charge a battery bank. That powers the mini fridge and a small TV so that after exercise one can slonk on the sofa and watch the match with a cold can or three?  :)