Not recieving serial data from ESP8266

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

FriendlyPotato
Posts: 8
Joined: Mon Feb 26, 2018 11:45 am
Been thanked: 1 time
Contact:

Not recieving serial data from ESP8266

Postby FriendlyPotato » Thu Apr 26, 2018 10:03 am

Hello. I am currently trying to make a moodlight controlled from the internet. The idea is that my ESP8266 check with the website every 10 seconds in order to figure out which command to perform. The data from the website is returned as a single character from a to p. This part works as intended.
Then the ESP should send the character via serial to my PIC16F628A, which should recieve it and do something.

The connection between website and ESP works and my flowcode program is set up as I want it, but the serial connection between the ESP and the PIC does not seem to work, no matter what I do. The TX port of the ESP is ofcourse connected to the RX port of the PIC.

Can anyone help with this?

I've attatched my latest flowcode file, and here is my ESP8266 code (serial is sent on line 45):
https://pastebin.com/2DyF3qAN

Best regards,
Friendly Potato
Attachments
RGB-chip-med-ESP8266.fcf
(34.33 KiB) Downloaded 49 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8376
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Not recieving serial data from ESP8266

Postby medelec35 » Thu Apr 26, 2018 11:33 am

Hi Friendly Potato,
If I need to receive UART from a source then I always use RXINT interrupt.
Chances of TX data start bit occurring at the exact time of RX component within a loop is very low indeed.. practically 0
Without that interrupt you will find it a struggle to get it working.

Martin
These users thanked the author medelec35 for the post:
Benj (Fri Apr 27, 2018 12:32 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

FriendlyPotato
Posts: 8
Joined: Mon Feb 26, 2018 11:45 am
Been thanked: 1 time
Contact:

Re: Not recieving serial data from ESP8266

Postby FriendlyPotato » Wed May 02, 2018 9:38 am

Hello, thank you for the reply.
I have tried implementing the RXINT, but since I have limited experience with interrupts in general, I am having a hard time getting it to work. Would you perhaps be able to explain more in depth or provide me with an example?
Thank you so much.

Best regards,
Friendly Potato

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8376
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Not recieving serial data from ESP8266

Postby medelec35 » Wed May 02, 2018 3:11 pm

Hi Friendly Potato,
All you do is drag the interrupt on you flowchart in Main and above the main loop.
Double click the interrupt, then select RXINT
Select Create New Macro and name the new macro e.g RXINT, then OK, OK & Edit Macro
Within RXINT macro, drag a ReceiveRS232Char and ender the name of your variable e.g ReceiveUART, select OK .
Now drag a calculation box to below the ReceiveRS232Char and enter

Code: Select all

ReceiveUART = ReceiveUART - 48

That's all for the interrupt.
Now ReceiveUART will pick up any characters being sent.
I normally use ReceiveRS232Char
If you need to receive string, then just use

Code: Select all

ReceiveRS232String

Just enter maximum number of bytes and timeout.
You will receive string values with not issues

If you get stuck, then go as far as you can then post flowchart.
Will then see if I can assist further.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

FriendlyPotato
Posts: 8
Joined: Mon Feb 26, 2018 11:45 am
Been thanked: 1 time
Contact:

Re: Not recieving serial data from ESP8266

Postby FriendlyPotato » Mon May 07, 2018 9:28 am

Hello medelec35.

Thank you so much for taking the time to help out.
It is still not working, even with the interrupt. I have included the latest Flowcode file and Arduino code.
The character which is returned from the web and passed along to the PIC is a single character from a to n.

Best regards,
Friendly Potato
Attachments
sketch-jan2018.txt
(1.21 KiB) Downloaded 38 times
RGB-chip-ESP8266.fcf
(40.56 KiB) Downloaded 46 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8376
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Not recieving serial data from ESP8266

Postby medelec35 » Mon May 07, 2018 11:51 am

Hi Friendly Potato,
Best to take it a step at a time.
One issue with your flowchart is having the same functions within interrupt as outside of interrupt will definitely cause issues.
E.g Compare$ in both

Code: Select all

RECEIVE
&

Code: Select all

Main
will cause corruption issues.
When you compile you will see:

Code: Select all

Building CASM file
Serious Warning: Possible sw stack corruption, function 'FCI_COMPARE' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCI_SCOPY' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

Can you remove or disable everything within interrupt except for RS232 Receive function.
You have also got

Code: Select all

esp_input = Left$ (esp_raw,1)

However you are only receiving one char at a time so that function is useless.
My suggestion would be just receive the char then monitor what char is received.
Either use LCD or RS232 monitor like Tera Term assuming you have UART to USB converter.
Make sure char received is the same as one sent.
We can then take it from there.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

FriendlyPotato
Posts: 8
Joined: Mon Feb 26, 2018 11:45 am
Been thanked: 1 time
Contact:

Re: Not recieving serial data from ESP8266

Postby FriendlyPotato » Tue May 08, 2018 10:54 am

Hello.

I have attatched my latest attempt which is still not working.
I have switched over to RecieveChar and made the code much simpler, but it still dosen't work.

It is set to recieve char and then check if it equals 97 (a) and then do something, or if it equals 98 (b) and so on.

What am I doing wrong?
Attachments
RGB-chip-med-ESP8266.fcf
(32.26 KiB) Downloaded 40 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8376
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Not recieving serial data from ESP8266

Postby medelec35 » Tue May 08, 2018 11:01 am

Have you completed a one second flash test to determine if hardware is running at the correct speed?
Do you have a scope so you can send a "U" and check baud rate is correct?
Are you able to display received char on a LCD or via a serial monitor?
It's best to check what character is being received.
You can also place an output within interrupt so LED lights when interrupt is received.
At least then you know interrupt is working.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Benj
Matrix Staff
Posts: 14219
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4361 times
Been thanked: 4096 times
Contact:

Re: Not recieving serial data from ESP8266

Postby Benj » Tue May 08, 2018 5:06 pm

To add to Martins post, is your Baud rate correct? The default baud for the ESP8266 modules is 115200 and you currently are using a 9600 baud.

A cheap scope with packet decoding can be invaluable for dealing with comms issues like this.

FriendlyPotato
Posts: 8
Joined: Mon Feb 26, 2018 11:45 am
Been thanked: 1 time
Contact:

Re: Not recieving serial data from ESP8266

Postby FriendlyPotato » Mon May 14, 2018 3:25 pm

Hello.

I've done a lot of troubleshooting and it seems that the problem lies in the RS232 component. It is now able to recieve serial from ESP or straight from command prompt in windows, and change color accordingly. However, after recieving the first command and changing color, none of the following commands work. I've tried inserting a loop at the bottom of my code, to empty the buffer, but that dosen't work.
I've tried sending serial straight from command prompt, without any flowcode code to save the input, but it still sticks to the first color it changes to, aka. the RS232 component is keeping the first input and not letting it go as it does in the simulation.

Any idea how to fix this?

Best regards,
Friendly Potato
Attachments
RGB-chip-med-ESP8266.fcf
(33.33 KiB) Downloaded 32 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8376
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Not recieving serial data from ESP8266

Postby medelec35 » Mon May 14, 2018 3:42 pm

Hi.
Simulation wont work with RX Int, it never has.
What I believe you need to do is clear the received variable once is has completed the Yes branch of

Code: Select all

96 < InputUART && InputUART < 111

Otherwise if RX int is not called again, the received variable will not change.
The confusion arises because the ReceiveUART was within main for testing and when there is no RS232 chars present it defaults to 255
On hardware the RS INT is not activated when no RS232 chars present so it will not assign variable with 255 like it did in your simulation.

See if attached is any better.

Martin
Attachments
RGB-chip-med-ESP8266 .fcf
(33.21 KiB) Downloaded 42 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

FriendlyPotato
Posts: 8
Joined: Mon Feb 26, 2018 11:45 am
Been thanked: 1 time
Contact:

Re: Not recieving serial data from ESP8266

Postby FriendlyPotato » Mon May 14, 2018 7:56 pm

Hi again.

Thank you, but I think you misunderstood my problem.
InputUART is supposed to hold on to the given int, until RecieveUART gets another one within the numer-range that we want. The problem is that after recieving the first letter from serial, eg. "f", the RS232 component dosen't seem to register anything else beyong that, it just keeps the "f".
We tried running the code without the decision and InputUART, and it still stayed on "f", or whatever else it recieved first.

Here's an example:
We ran the code without the decision associated with InputUART and just made it equal to RecieveUART instantly. We then sent "l" which turned the LED pink. Then we tried sending "a" in order to change the LED to red, but it stayed on pink. We had to cut the power, start it up again and then send "a" in order for it to be red.

It is really weird and we hope you know why it is doing this.

Best regards,
Friendly Potato

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8376
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Not recieving serial data from ESP8266

Postby medelec35 » Tue May 15, 2018 6:46 pm

I have tried the flowchart I sent with

Code: Select all

InputUART = 0
removed
Just for test purposes it's working for me with LCD output.
I pressed a letter and correct char is always displayed without resetting, using this flowchart:
RS232 LCD.png
RS232 LCD.png (109.1 KiB) Viewed 1763 times

I am using a 16F1937 target
Results after sending abcdef (greater than 5 sec delay inbetween each character :
Results.jpg
Results.jpg (288.14 KiB) Viewed 1760 times

Are you taking into account that if within 5 seconds you have the delay set for, if received chars is abcd, then only the d will be used.
abc will be ignored.
Do you want to changed the way this works or is the time the chars sent greater than 5 seconds?
Is there a reason for the 5 second delay, as the last char is stored?
You may find it works better if greatly reduced delay to sat 100ms
These users thanked the author medelec35 for the post:
LeighM (Thu May 17, 2018 8:57 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.