Go Down

Topic: What language do I use? (Read 4091 times) previous topic - next topic

K3IHI

I am using and arduino with wifi and port forwarding. My goal is to be able to create a web based program that will communicate with my arduino wirelessly to control a sunrise sunset affect with an led array. I want the program to be accessible anywhere and I want to be able to interrupt the program for set periods of time like a storm for example and then have the program go back to its normal original program(sunrise/sunset)

I am a beginner at programming I have my arduino set on a timed program not on a clock and I'm getting my wifi shield and I need help getting started. Anything with be greatly appreciated.

Thanks

PaulS

Quote
What language do I use?

The Arduino is programmed in C++ (which is a superset of C). The Arduino has to be programmed to served up, and respond to, a web page which is coded in html. But, html is text based, so you will be sending text that some other computer sees as a distinct language.

This is not beginner programming, if you have never done web programming, web page design, client/server communication, or (as appears to be your case) any programming.

dxw00d

#2
Jan 11, 2012, 04:28 pm Last Edit: Jan 11, 2012, 04:33 pm by dxw00d Reason: 1
You know, someone could make a killing selling an aquarium control shield, given the number of posts on here on the subject. An RGB LED string driver, an RTC module, perhaps some relays for air pump control and feeders, with a library to tie it all together.

K3IHI

In a nut shell that is my overall goal. A complete stand alone module that can control lights. Next would be the I/o for pumps probes ect. I need to first figure out what I need to learn programming wise before I get in over my head too fast. So c++ and then I need to convert HTML a text language into c++ where next?

Grumpy_Mike

Quote
then I need to convert HTML a text language into c++

No.
HTML is a text language, you have to make sure that your arduino serves up this language on request from a web client.

Quote
before I get in over my head

I think you were there a long time ago if you don't know what language an arduino uses.

Forget your project for a moment and get a wi-fi shield and go through the various examples using it. Learn that first.

PaulS

Quote
Forget your project for a moment and get a wi-fi shield and go through the various examples using it. Learn that first.

I've got to disagree, Mike. The wifi shields are not beginner devices. Learning to blink LEDs is first. Then, learn to send data to the serial port, and receive a response. Then, learn to collect that response into a string. Then, learn to parse that string, and do something with the parsed data.

Then, as a completely separate activity, learn to develop web pages. Then, learn to develop functionality to be called when the submit button is pressed.

Then, get an ethernet shield, and learn to make the Arduino serve the web page, and respond to submissions.

Only then would one get a wifi shield, and make the Arduino wireless.

Grumpy_Mike

Quote
I've got to disagree, Mike.

Yes you are probably right to disagree with me on this.  ;)

Maybe you could help, I am three and have just learned to walk. How can I run 6 Marathons in 10 days?

cr0sh


In a nut shell that is my overall goal. A complete stand alone module that can control lights. Next would be the I/o for pumps probes ect. I need to first figure out what I need to learn programming wise before I get in over my head too fast. So c++ and then I need to convert HTML a text language into c++ where next?


No - It's a little more complex than that.

First off - what do you mean by "communicate wirelessly with the Arduino"? Do you mean over wifi, xbee, some kind of RF module - something else? The choice there will determine how you communicate with it.

For example, using a wifi module would mean communicating via network message passing, whereas the latter two might mean using a serial port of some kind.

Know this may influence what language(s) you can use on the PC end of things (it may even determine what OS platform you can use; for instance, it is very difficult to perform 2-way serial comms under Windows - not impossible, but they don't make it easy for some reason, either - especially if using PHP); most languages have the necessary interfaces and libraries for both serial and network messaging, but you should plan this carefully.

Also note that once you even know that, you may also need to know how to set up and use a communication protocol to communicate with the Arduino. Fortunately, there are some good libraries out there for both ends (because you need to do this both on the PC side and the Arduino side) of the chain.

As far as programming is concerned, on the Arduino side, it's essentially C/C++; play around with the demos, read some tutorials, etc - but I wouldn't go "whole-hog" into in-depth C/C++ programming tutorials meant for the PC. C/C++ on a microcontroller (especially one like the Arduino where a lot of stuff has been abstracted away for you) is a vastly different beast from doing the same on the PC (mainly due to memory and other resource limitations compared to a PC). So - learning C/C++ programming for the PC may actually hinder your understanding of doing it on a microcontroller (and vice-versa, unfortunately). Keep the differences in mind, though, and you might find that even PC tutorials may be helpful for some things.

On the PC side of things, for a web application, your choices are much broader. I would -not- recommend attempting to do web development using C/C++; while it is possible, for the tasks you are facing it is very much overkill. I would actually say for your application, using PHP or Python (or even a combination) would be the best solutions. Another solution might be Processing (note that Processing is essentially C/C++, which may seem like I am contradicting myself - I only mention it, though, because it is an abstracted form of C/C++ much in the same way the Arduino platform is, which is why the Arduino platform was based on it; thus, it may be easier to learn both the Arduino and Processing in parallel - just something to keep in mind).

If you are windows-centric, there's also the possibilities of using Windows technologies (just be aware that you may limit yourself, and any future users of your system, by doing this). These would include ASP, ASP.NET, C#.NET, VB.NET - plus for DB stuff things like IIS/MSSQL or Access (you may also find connectors and ways to use open-source DBs like MySQL and Python).

At any rate, on the PC side (also note when I say "PC", I generally mean Windows, Linux, or Mac - but each has it own strengths), you'll need to learn a language for the coding of the web application that will communicate with the Arduino (in some manner - it may or may not -directly- communicate with the Arduino, or it may communicate with a service on the PC, which you would have to write, which would run in the background communicating with the Arduino; the advantage of this service method is that, if the service or your web app should fail, the whole thing wouldn't necessarily "freeze up" or otherwise totally fail - however, it is more difficult and complicated to implement). This web application would output (to the browser) an HTML page, which would display your information, and maybe have a form or two that you could submit data back to your web application, which would then act on it to send a message to the Arduino. It may also need to write this information out to a file, or to a database. So there are a couple more things to learn.

In short - here is a list of technologies you would need to learn:

C/C++ (for Arduino)

One or more of:

Processing (PC)
PHP (PC)
Python (PC)
ASP/ASP.NET/C#.NET/VB.NET (Windows PC)

For the web stuff:

A minimum of how HTML and CGI works
As well as (possibly) DHTML, Javascript, AJAX, POST/GET, etc.

...and a database (as well as how to write SQL), such as:

MySQL (PC)
PostgreSQL (PC)
IIS/MSSQL or Access (Windows PC)

...and/or:

General file handling (reading and writing files with the language on the PC you use), and serial or network communications and message passing.

Not too mention all the hardware interfacing and electronics. Also - I am sure I forgot something along the line here; everything written above is a very simplified list - there's much more to learn than just the languages and the syntax of them. You'll also have to understand synchronous vs asynchronous communications, event driven vs polling design, stateful processes (as well as how and why web applications don't hold state between requests, what that means, and how you work around it)...

As you can see - this is hardly a beginner's project. But, if you take it one bit at a time (while taking your time, asking questions, and gaining understanding), you can come up with a working system in the end. Just don't let the "grand scope" overwhelm you. Instead, start with the basics (the Arduino, and simple serial communications via the virtual USB serial port) to get a feel for the hardware end of things, and simple messaging via serial (and the terminal). Then you can move on to the PC side of things, and work your way around over there.

Good luck with your project!

:D
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

wildbill

You may find it a little more motivational if you can take some concrete steps towards building your project - look at your overall requirement and find the one simplest piece of it. Might well be your led array. Look through the examples to find help, also search the forums for other acquarium projects. Light a single led, then many, fade them with PWM. Gradually build it up until you have a standalone controller. Only then would I worry about the web.

K3IHI

To specify a few things:
1 I want to use a wifi shield
2 I have the basic program written and in use now but it's simply a timer based program that dims after certain delays and shuts off after certain specified amounts of time delays
3 I want to start out controlling the led array only
4 what is the simplest way to do this?


Maybe that will help

Thanks

Udo Klein

Controlling a bunch of LEDs --> go to my webpage www.blinkenlight.net
Using a WIFI or lan shield --> don't do it. An Arduino is to underpowered for a webserver. Also an Arduino + Shield will cost more than a stronger machine. Go for a cheap computer that already supports WIFI and connect the Arduino to it.
Guru plug, hacked WLAN routers and other computers come to mind.
Check out my experiments http://blog.blinkenlight.net

PaulS

Quote
An Arduino is to underpowered for a webserver.

That all depends on what is being served. For some small web pages, it works just fine.

For about $30 for an Arduino and $45 for an ethernet shield, it's hard to find another option for a better price.

Grumpy_Mike

This is wrong:-
Quote
An Arduino is to underpowered for a webserver

It should say:-
Quote
An Arduino is too underpowered for a webserver

Then it is just incorrect.

Nick Gammon


I am using and arduino with wifi and port forwarding. My goal is to be able to create a web based program that will communicate with my arduino wirelessly to control a sunrise sunset affect with an led array.


After re-reading that a few times I think this could be achievable with fairly minimal effort. As I read it, you are planning to have an Arduino somewhere (eg. in an office) where you have web access, via wifi (so I presume there is power around). Connecting the wifi to an Arduino ethernet shield could be done by an existing WAP (wireless access point) device, such as the one I use here at home to connect a non-wifi gadget (like a TV) to the wifi, where cables are not available.

You mention port forwarding, so it sounds like you know about that, and thus you have plans to communicate with your device from "outside" its local network. Say, you might be in the street a few blocks away holding a laptop.

Now you want to enter some sort of command on the laptop, which gets sent to the Arduino, which alters what it is doing, am I right?

The tricky bit will be to send the data and have the server understand it. The examples for the Ethernet card, as far as I can see, do not involve web forms. There are probably thousands of pages that explain that, but I investigated a while back when I was trying to do a Lua-based web server, some of my findings are here:

http://www.gammon.com.au/forum/?id=6498

To "send a web page" you need to send the HTTP headers, followed by a blank line, followed by the page, as a minimal example:

Code: [Select]
HTTP/1.1 200 OK
Date: Fri, 28 Apr 2006 03:14:58 GMT
Server: MyArduinoServer version 1.0
Connection: close
Content-Type: text/plain

Hello, world


To receive a HTTP request you need to parse the various headers you get from the web browser. I'm not sure how much of this the Ethernet library does for you, if any.

There is quite a bit of string manipulation involved, and playing with strings can be problematic when you only have 2 Kb of RAM. You would need to go for something pretty simple (like, very simple commands).

I would agree with the others, start simple, and work your way up. Don't try this particular project as your first one or you will get frustrated.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Udo Klein

Of course you can implement a web server with an Arduino. You can implement a web server with less powerful machines. True. But if you look at the other options I would not bother doing so. In my opinion it is way too restricted for a reasonable web server.
Check out my experiments http://blog.blinkenlight.net

Go Up