|
306
|
Topics / Home Automation and Networked Objects / Re: Gauge controlled with Ajax shows Not A Number error
|
on: March 25, 2013, 02:52:11 pm
|
Unless I'm mistaken, this javascript code, which runs in the browser, is trying to call GetPoolTemp(), a function from the Arduino C code. Which isn't possible, right? data-onready="setInterval( function() { Gauge.Collection.get('gauge1').setValue(GetPoolTemp());}, 800);"
Is the intention to send the actual temperature as part of the data-onready attribute? If so, you'll need to call GetPoolTemp() on the Arduino and insert its value into the page you send somehow. -br
|
|
|
|
|
311
|
Using Arduino / Project Guidance / Re: New to Arduino
|
on: March 22, 2013, 08:34:04 pm
|
|
May I offer some opinions?
1. Trying to "learn the language" in the abstract is hard and often not the best approach. At least not for me, and I've learned a few.
Learning a language "in practice", which is to say as a side effect of getting a project done, has a nice way of prioritizing the learning into just what you need at the moment. So, find a project, get stuck, hit Google, do a little just-in-time learning, repeat.
2. When you have a project in mind, your first stop should be Google anyway, to find out what else has been written on the same topic. Read all the code you can find - you get better much faster reading well-written, working code than by reading reference material. Finding a sample or reference sketch to start from can be very helpful.
3. A word on workmanship. Take the time to study coding styles, and pick one to use as your own. Apply it carefully in everything you write so your eyes will learn to spot discrepancies; this will save you half of your debugging time. Nothing says "newbie" more than code that looks like an unmade bed, and bugs love to grow in poorly laid out code. The compiler cares about every single character and so should you.
4. Debugging is as important as coding. Unfortunately, it is twice as hard, so if you write something so clever you don't really fully understand it, you won't have a prayer of debugging it. Favor simplicity in what you write and learn to use Serial.print() to confirm what's going on. It's cheaper to think about "How am I going to know whether this is working?" when you write it than later when you're debugging it.
My $.02. Good luck on your journey.
-br
|
|
|
|
|
312
|
Topics / Home Automation and Networked Objects / Re: control without port forwarding
|
on: March 22, 2013, 06:54:52 am
|
The BitlashRedisClient example that ships with Bitlash might be a useful source of ideas, even if you don't use the code, which is here: https://github.com/billroy/bitlash/blob/master/examples/BitlashRedisClient/BitlashRedisClient.pde (and more about Bitlash here: http://bitlash.net) Here's how it works. Redis is an in-memory database server with publish/subscribe capabilities. You set up a Redis instance somewhere (on your web server, or maybe a free one from http://RedisToGo.com). Your Arduino connects to the database and listens for commands (by subscribing to a command channel). Then your PHP web application connects to the database and sends commands to the command channel as needed. Any arduinos connected to the channel receive the commands to be executed. (There are libraries that make this easy on the PHP side.) The key feature that allows this to work around firewall issues is the persistent outbound TCP connection from the Arduino to the database. Unlike an HTTP connection which comes and goes for each request, the TCP connection can hang around as long as you like, so the arduino is in effect always listening for another command. In the BitlashRedisClient example, the data that moves over the wire is Bitlash commands, but of course it can be anything. Hope this is helpful; good luck with your project. -br
|
|
|
|
|
313
|
Using Arduino / Programming Questions / Re: Unions+Functions+serialWrite = Error
|
on: March 21, 2013, 05:07:03 pm
|
I think you were being bit by some variant of the "precompiler rearranges your sketch" bug. I got your last code to compile by adding a line defining SendMidiMsg(); see below. I got there by looking at the .cpp that is actually compiled for the project, which you can get from rummaging around in the build folder, which you can identify by turning on verbose builds in Preferences. The precompiler phase moved the definition of SendMidiMsg above the definition of the union, which made the compiler unhappy. It seems better here with the patch. -br #include "arduino.h"
#define _C4 0x30 #define _Cs4 0x31 #define _D4 0x32 #define _Ds4 0x33 #define _E4 0x34 #define _F4 0x35 #define _Fs4 0x36 #define _G4 0x37 #define _Gs4 0x38 #define _A4 0x39 #define _As4 0x3A #define _B4 0x3B #define _C5 0x3C #define NoteOn 0x7B #define MaxVel 0xFF
typedef union { struct { uint8_t Command; uint8_t Channel; uint8_t Data1; uint8_t Data2; } Msg; uint8_t Raw[4]; } MidiMsg; void SendMidiMsg (MidiMsg* Message); // this is the magic line
void setup() { Serial.begin(31250); }
void SendMidiMsg (MidiMsg* Message){ Serial.write(Message->Raw, sizeof(*Message)); }
void SendNoteOn (uint8_t Note, uint8_t Velocity, uint8_t Channel){ MidiMsg Message; Message.Msg.Command=NoteOn; Message.Msg.Channel=Channel; Message.Msg.Data1=Note; Message.Msg.Data2=Velocity; SendMidiMsg(&Message); }
void SendScale (int ValveState){ uint8_t Vel=MaxVel; uint8_t Ch=0x00; switch (ValveState) { case 0: SendNoteOn(_C4,Vel,Ch); break; case 1: SendNoteOn(_D4,Vel,Ch); break; case 2: SendNoteOn(_F4,Vel,Ch); break; case 3: SendNoteOn(_E4,Vel,Ch); break; case 4: SendNoteOn(_A4,Vel,Ch); break; case 5: SendNoteOn(_B4,Vel,Ch); break; case 6: SendNoteOn(_G4,Vel,Ch); break; case 7: SendNoteOn(_C5,Vel,Ch); break; } } void loop(){ SendScale(0); }
|
|
|
|
|