Notifications
Clear all

[Solved] Hello from Northumberland, UK

42 Posts
6 Users
23 Reactions
2,002 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@byron I thought CAN bus was supported, why bother with low level UART?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
 

@swarlandrb

my quick reply on your 'b question, whilst I hope it clarifies those persky b' is maybe better answered by the following (yes I'm ducking out of painting a couple of doors right now, just don't tell SWIMBO)

Most communication between computers is achieved by sending a stream of bytes.  So in my example of the sending data I converted the counting of the range from 0 to 20 to a string which is a number of bytes.  If I want to just send a number I have to convert it to a stream of bytes.   At the receiving end I have to convert the stream of bytes to a number.  So at the risk of a bit of seemingly funny code like 'mybytes = int.to_bytes(x,1,'big')' I give you another two bits of code for your pico's that may work better for you.

Sender:

from machine import UART, Pin
import time

uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))

while True:
    for x in range(20):
        mybytes = int.to_bytes(x,1,'big')
        uart0.write(mybytes)
        print(x, 'was sent')
        time.sleep(5)

 

Receiver:

from machine import UART, Pin
import time

uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))

while True:
    if uart0.any():
        data = uart0.read()
        print('uart data received was', int.from_bytes(data, 'big'))
   

The time.sleep in the sender is just so that the print output does not wiz passed too fast.

I hope this helps.  No more pesky b' strings are shown.

This post was modified 2 years ago by byron

   
SwarlandRB reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
 
Posted by: @zander

I thought CAN bus was supported, why bother with low level UART

Extra hardware for starters, but why is the CAN bus a higher level than UART?  I far as I can see both transmit / receive a steam of bytes although uart is asynchronous whereas the CAN bus can be both asynchronous and synchronous. (but as you say we want asynchronous anyway) But as I've not actually coded up the sending and receiving of data on a CAN bus I don't speak with authority.  You will need to show CAN bus programs in micropython (which is a stated requirement ) before I consider doing the CAN CAN 😋 😞 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@byron Perhaps I am mistaken, I thought UART was just an unstructured bit stream and CAN BUS is a structured protocol.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@byron CBUS is built on top of CANBUS.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
 
Posted by: @zander

CBUS is built on top of CANBUS.

Yes, as I observed in an earlier post.  I tell you what, if you provide a video of you doing the CANCAN, I will look into it in more depth. But for gawds sake make sure your underwear is properly adjusted first.  (shudder)


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 
Posted by: @byron

Yes, as I observed in an earlier post.  I tell you what, if you provide a video of you doing the CANCAN, I will look into it in more depth.

That's it !! I'm calling the Vice Squad 🙂

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
 
Posted by: @will

That's it !! I'm calling the Vice Squad 🙂

But I know I'm on a safe wicket as dear Ron ( @zander ) would not be able to kick his leg up too high at his age.  Well I blooming well hope not. 😲 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@byron I couldn't kick it that high a long time ago. Today I am more likely to just fall over.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

@zander 

Thank heavens 🙂

I'll call off the alert, open the curtains and shut down my screensaver 🙂

Anything seems possible when you don't know what you're talking about.


   
byron reacted
ReplyQuote
(@swarlandrb)
Member
Joined: 2 years ago
Posts: 11
Topic starter  

@byron 

Many thanks once again. I thought I would try the number just as it arrived from Pico 1 to Pico 2, into a switch command on Pico 2 after being converted into an integer and it works fine just as it is.  The 'b' seems only to be there when the uart buffer is printed out.

I now need to combine my test modules, tidy up the code, comment/document it and we'll be good to build the control panel and install on the layout. It's a good job the snow has arrived to prevent the gardening getting in the way, (but not bad enough to stop a 7 mile trip into our nearest town for the SWMBO's hairdo appointment! )

@byron Once again my thanks for all your help, it has been a godsend to me.  I will now mark this thread as solved.

Cheers, Roger


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
 

@swarlandrb

Hi Roger, good to hear its all working.  I think maybe I gave a bit too much unnecessary info regarding the b. binary string and hope it did not confuse.

 As you found it only prints the b. when the string is sent as a stream of binary data, and to show the string in the correct unicode format UFT-8 (the default) for us, or UFT-someOtherNumberr for those languages that use accents etc.  So as per the first example I showed you would just return it to the UFT-8 format with a 'data.decode()' or as you have done, turn it into a integer number with 'int(data)'  But I'm probably waffling on again 😋 .  

We possibly has some snow before you as at midnight last night we put the outside light on to see one of those really nice snow scenes with large fluffy snowflakes  gently coming down.  Your forgiven for not keeping the snow up north as it was nice to watch.


   
SwarlandRB reacted
ReplyQuote
Page 3 / 3