CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Communication between 18F4550 and WiFi module ESP8266-01

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

Communication between 18F4550 and WiFi module ESP8266-01
PostPosted: Fri Apr 01, 2016 11:45 am     Reply with quote

Hi everyone!

I'm trying to communicate my pic 18f4550 via wifi with my computer using the module ESP8266-01.
I want to ask if someone has tried this, because I'm not able to find any example about how to connect both components.
ESP8266-01 works using RX and TX pins to communicate, but I don't know how to program this communication using this pic.
I was able to configure the module with an Arduino Nano, I have the IP address of the module and I have configured it with my wifi network.
I only want to try a simple blinking led via wireless, because knowing how works that communication, I will be able to understand how this module communicate with any component.

Someone could help me with this little project?
Thanks a lot!

Daniel Lozano.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Apr 01, 2016 12:13 pm     Reply with quote

Its regular 9600 serial with the ESP through the UART.
from what i understood you want ON/OFF control over wifi of a LED.

for this, you first need to understand how to configure the ESP via AT commands.
The IP address is assigned by your router... not the ESP or your code.

after you have managed to get your ESP to link to your Router AP, you will then need to configure your ESP as a SERVER... and have it reply with a HTML webpage to GET requests (this requires alot of text parsing) ... but this is way harder than it looks... at least to do reliably because regular browsers send 2 GET requests sequentially... one for the Web page and one for the FAVICON.... google that... and handling the Favicon is a pain in the rear.

start simple, and post your efforts.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
lozi_dani



Joined: 22 Jan 2016
Posts: 40

View user's profile Send private message

PostPosted: Fri Apr 01, 2016 12:53 pm     Reply with quote

I have started from the beginning. I'm going to tell what I have now, and what I want to achieve. Sorry if I have not explained well first.

I've made some projects with 18f4550, so I know how to program some component and how works some of the configurations of this pic. What I'm trying to do is start to program something using IoT (it's my first time doing this).

So, let's start from the beginning:

1. I've an Arduino Nano, which I have used to configure my ESP8266-01 via Arduino code inside the Arduino Nano, and after, using AT commands to configure the ESP8266-01 using the virtual terminal of the Arduino IDE.
2. Via AT commands, I've asked to the ESP8266-01 which baud rate is using to have a legible answer. It can works between 9600 and around 96000, I don't remember very well the higher baud rate can use. And also, via AT commands I have answer which baud rate is using now, and it answered me 9600. So I know which baud rate I need to use in my pic.
3. I have an html code which show me two buttons, ON and OFF. This buttons will turn on and off my led, and I have achieved it using the Arduino I have mentioned.
4. I've tried first this using Arduino before my 18f4550 because I've seen some useful example which helped me to understand how ESP8266-01 works.


Now I'm going to do my question again. Maybe with this info I'm giving you will see that I have started from the beginning and I'm not asking with no knowledge.


I want now to connect my ESP8266-01 with my pic 18f4550. I've not seen any example about this. Neither how to connect it not how to program it.

So, someone could give some useful info or some first examples or advices to start with this?

The only think that I want to know is if someone have tried this or maybe know where I could start, because I don't know how to export what I did in Arduino to CCS, because in Arduino everything is given, all the examples and codes, but in CCS I know that it is a little bit more difficult.

I'm sorry if I have not explained well at the beginning where I am and what I want to achieve.

Maybe you know how can I start because I have not idea 😭

Thanks for the quickly answer!! This forum never disappoint! =)
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Apr 01, 2016 2:06 pm     Reply with quote

Hi,

Coincidentally, I have two ESP8266 projects on the bench right now. One is used to sync a Nixie clock time using an NTP time server, and the other is a remote Temp/Humidity sensor that posts data to the ThingSpeak data service.

Anyway, get your hardware squared away first! The ESP8266 is a +3.3V device, so you can make your life a whole lot easier by using a PIC that also runs at +3.3V. The easiest way to go about this is to simple obtain the 'LF' version of the same part you are using! The PIC Tx goes directly to ESP8266 Rx, and PIC Rx goes directly to ESP8266 Tx.

I would also HIGHLY recommend that you start by connecting the ESP8266 to your PC serial port via a MAX3232 (or similar), and playing with the AT commands before you connect to your PIC. In this way you can experiment with exactly the required AT commands, and you can clearly see the resulting responses!!
_________________
John

If it's worth doing, it's worth doing in real hardware!
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Apr 01, 2016 3:37 pm     Reply with quote

EzFlyr:

ive got quite a few remote units loading data to thingspeak too!
we should compare methods!
any chance of you sharing that NTP time acquisition routine?
what server are you using? i tried this... no success.


On topic:
Arduino, CCS, or what ever your compiler choice, the ESP control is the same. AT via serial... literally just send the same "Arduino" commands.
This is how i got started.

Are you currently able to send serial data to a PC terminal?
Do you own a Pickit 3 or other programmer?


I apologize if my post sounded condescending... just trying to figure out where you are on this...

Post your current CCS Code.
lets start here.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat Apr 02, 2016 7:47 am     Reply with quote

Hi Gabriel,

What is your need for time accuracy? This is important because, IMHO, using an NTP time server is a PITA! I used one of the US Gov. NIST time servers in Boulder CO, and had to jump through all kinds of hoops to become an 'authorized' user, including registration by snail mail...... If you can live with accuracy within a few hundred milliseconds, I've implemented a very easy 'hack' to do this! Basically, it involves sending a general HTTP request to a server (I use 'Google.com') and then extracting the time/date info from the reply header! Larger, well-known & busy sites like Google are going to be getting their time using NTP, so in effect, you are letting them do the 'heavy lifting' with their servers, and then extracting the time/date info using much simpler methods.....

BTW, how are you setting the WiFi info on your projects? Mine have a USB port for this task, but I'm looking at a slicker alternative now. Basically, the ESP-8266 will check to see if it has an IP address upon booting, and if not, will boot in AP mode. In AP mode, remote devices (Smartphones, tablets, etc.) can connect and set the WiFi info. The ESP-8266 will then reboot in STA mode. Still working out the details on this, but if you are interested, I'll keep you posted!
_________________
John

If it's worth doing, it's worth doing in real hardware!
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Apr 02, 2016 9:32 am     Reply with quote

I too solved my problem with the google header for time! jejeje but didn't use this solution in the end.

Since I'm running both a GSM/GPRS modem and ESP on the same PIC, I SMS the WiFi credentials to my modules, i also use the incoming SMS time stamp to update the local clock... i can live with 1 - 3 minute error... local carriers are always sms-ing prepaid sims with unsolicited crap, so the clock gets sync for free a couple of times a day.

I have not been able to find a decent solution to the "Favicon" problem so i haven't finished (i side tracked the project) my AP boot code.
how did you handle that?

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Apr 03, 2016 10:27 am     Reply with quote

Hi Gabriel,

I'm not sure what you mean by the 'Favicon' issue? Are you referring to additional date sent with the HTML header packet? If so, I have a routine that looks for the specific date/time string in the reply data, and basically ignores everything else!

As for the AP mode of operation for gathering WiFi credientals, I'll PM you a link so that we don't drag this thread too far OT!
_________________
John

If it's worth doing, it's worth doing in real hardware!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group