Notifications
Clear all

ESP32S3 Serial Communications

25 Posts
4 Users
7 Likes
1,155 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@huckohio What language is that?

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.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
huckOhio
(@huckohio)
Member
Joined: 5 years ago
Posts: 180
Topic starter  

@zander The ESP32S3 code is standard Arduino (I think C or C++).  The Pi4 code is python 3.x.


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

@huckohio I found encode and decode in python and see no reason for you to be using them.

A more general comment. Without line numbers and the name of the file I have no idea what piece of code you are talking about.

If no other way, do a small selected screen print that shows the line numbers.

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.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


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

@huckohio If you KNOW a piece of code is causing you a problem, post the chunk (10 to 20 lines) with the name of the file and line numbers.

I am not python trained, but I will probably understand it to some degree.

Remind me again what is the specific problem you are having?

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.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
huckOhio
(@huckohio)
Member
Joined: 5 years ago
Posts: 180
Topic starter  

@zander Ron, I'll get the code segments tomorrow.  My problem is the data from the raspberry Pi 4 is not arriving at the ESP32S3 in the rabbit shed.  

I'll look into the use of encode/decode.  It was used in the example I found on sending data between the Pi4 and arduino.


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

@huckohio The normal way I would try to debug something like this is reduce the code to just the function that is new and unknown, no gui or printing, just send a test message on one side, and receive test message on the other. The message should be text only, no math types. The usual message is "Hello World". Once that is working make the message sent richer and you may not have the skills to see all of it but just changing data types does not alter the send/receive function. Now there may be a learning curve but unlikely a bug in dealing with other data types. At some point we need to reorder the structure members into a more efficient order, most strict alignment to least strict. Don't worry about it for now though.

So bottom line just the code to send a msg and receive a msg with msg being the string "Hello World"

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.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
huckOhio reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1683
 

Hi @huckohio,

  I agree with what Ron has said in his numerous replies ... but, for your specific question

" I've never used encode and decode  .... Really not sure what they are doing"

I wasn't sure either, but I did a quick Google that might be helpful to you ... and landed on:

https://www.w3schools.com/python/ref_string_encode.asp

In case you haven't met w3schools before, I would just say it is a really helpful site for figuring out what a particular command does in any one of several languages ... and as well as being a 'dictionary' of commands, it includes interactive script pages (hit the "Run Example" button on the page I have pointed to) with examples of the command, that you can edit and hit the 'run' button to immediately see the effect of your edits.

From this, it is clear that encode and decode are a way of 'protecting' characters whilst they are transmitted over a link.

To explain a little of why encode can be helpful: When you send (or save in memory) a character, say 'A', you actually send a number as 'code' equivalent ... the 'usual' code is ASCII, and an 'A' has the value of 65 in decimal (0x41 in hexadecimal). The code for 'B' is 66  (0x42), and so on. 

This is nice and easy, if you stick to A-Z, a-z 0-9, plus some common punctuations/symbols like $ % , or .    

However, the number range that fits in the 'usual space' (which is actually 8 binary bits or 1 byte) allocated to each character, is limited to the integers 0..255, so the number of possible symbols, international letters and so on, greatly exceeds the 256 available codes.

The 'solution' (or more accurately 'solutions', as there are many variations on the same theme), is use more than one 'space' for a single character ... because two 'spaces' allows a range of 256 x 256 = 65356, 3 'spaces' allows more 16 million, and 4 'spaces' more than 4 billion.

The obvious disadvantage is that using just 2 'spaces' or 'bytes' instead of one, doubles the amount of memory or the time taken to send a single letter over a data link ... so if your communications are 99.9%-100% 'simple ASCII A-Z a-z 0-9  etc... ', then using 2 bytes per character is halving the speed of the data link or doubling the memory requirement with little to no benefit.

The trick that encode is doing, is to take a string, which may include characters not included in the simple range, and encode them as sequence of characters that are ASCII ... and obviously decode reverses that process, to get back to the original.

-----------------

So what is the benefit for your program ... looking at it quickly, it is not clear that ithas a value in, many cases, though the effect may be relatively harmless, because you are sending a lot of strings like "Fan1Dis", that shouldn't be a problem to simple ASCII, and hence do not need the complication and work of encode/decode.

The tricky ones tend to to be either characters from non-English characters (as illustrated by the W3schools page) or values from sensors.

A sensor will often return a number ... a switch may return a 0 for open and a 1 for closed, and a 8-bit analogue to Digital (A/D) converter a number between 0 and 255, depending upon the voltage it is measuring, and so on.

However, these returned values are not ASCII encoded .. they are 'raw' numbers ... so if they are sent over a link expecting ASCII characters, they may be misinterpreted. e.g. if the A/D returned a value of 65, then printing that value directly would show a single 'A', not a string saying "65".

Even worse, some values in the ASCII range are not printable, e.g. the value 0, which is a kind of 'null' character in ASCII, and is often used to denote the end of a string. So sending the raw values from an A/D over a system that is expecting ASCII strings is inviting all kinds of misinterpretation.

If the '65' value was encoded and decoded, then the decoded value would still be a single byte value, but would not have been misinterpreted on the way.

Hence, now you have at least a partially working system, I suggest you 'audit' the places encode/decode is used, and see if you can remove (most of) them .. I would do it 'one at time', just in case there any exceptions! (I only glanced at your program ... so there might be a few hiding in plain sight!)

------

A long sermon, but I hope it is useful and helpful.

Best wishes, Dave


   
huckOhio and Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@davee Ron's short answer is you do NOT need encode/decode but it will not hurt to leave it in.

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.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
DaveE reacted
ReplyQuote
huckOhio
(@huckohio)
Member
Joined: 5 years ago
Posts: 180
Topic starter  

@zander @davee  Thanks Ron and Dave for the suggestions.  I will look at sending the data without encoding/decoding figuring that if I can get the house ESP32S3 to pass data correctly to the Pi4 then sending the data back should be no problem.  My quick look at pySerial is that it requires encoding, but I'll look into that again.  

My challenge is with the ESP32S3 connected to the raspberry Pi4 I cannot hook the ESP32S3 up to a computer - I think the error I received was serial port exception.  You've both given me vectors that I can run with and continue my work on passing the data.  Thank you both.  More to follow.

Mike


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

@huckohio Like I said, work on a simple test case first without all the overhead. Once you can do that then it will be much easier. In 50 years of coding including supporting 100's of comms lines at once from many different suppliers, never used an encode or decode even once. IIRC, it's just a WWW thing.

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.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
huckOhio reacted
ReplyQuote
Page 2 / 2