Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Programming Questions / Re: IF temperature > 24 --> hot hot hot on: March 15, 2013, 12:42:45 am
I don't see how that code would flicker quickly between the two texts unless you call once a second quickly. But it depends on how exactly you added that second line into the sketch because that line wouldn't even compile. You need an if else and make it so that at least when anything should change on screen, it also clears the line that used to have text on it, or writes on top of it, but not both at the same time.

Secondly, from what I've seen, temperature sensors can produce spikes or drops. Suddenly the reading would just drop by up to several degrees in my tests. You can add a check on passed time so that your printed line possibly cannot flicker too quickly between states.
2  Using Arduino / Programming Questions / Re: help with alarm code on: March 14, 2013, 03:40:17 pm
you mean something like this???

Code:
char* msg;
Is that what you tried and got all those errors? It looks most correct for what you seem to be trying to do. It's a pointer. Initialize it to 0 just in case.

Next you need to see what code sits on the line number it whines about, if it still does. I suspect the error messages point to all the lines where you are trying to assign something to msg and that's what you tinker. I can't tell off the top of my head at this hour what's it supposed to read for what you are doing there. I assume you are trying to assign the other array pointers to the msg one, so do that.

It's only going to work if twitter.post(msg) accepted a char pointer. I can see it takes a const char pointer judging by the error message. Well, see what the compiler tells you anyways without making too many changes at once between each compilation.

Another thing, if you end up getting a whole bunch of text posted (all of the strings), you probably need a null ending character \0 at the end of the string of characters. Or maybe not, I forget as I rarely have to deal with char arrays in C these days. Can you find out and post your findings?
3  Using Arduino / Programming Questions / Re: data overflow on: March 12, 2013, 03:31:33 pm
Code:
  float rulex1, rulex2, rulex3, rulex4, rulex5, rulex6, rulex7, rulex8, rulex9, rulex10, rulex11, rulex12, rulex13, rulex14, rulex15, rulex16, rulex17, rulex18, rulex19, rulex20, rulex21 =0;
Take a close look at this line. See the init only on the last float? You have an overflow because all the rest are random. I'm sorry but the code was a little tl;dr with too many variables for me to be able to tell where they all still initialized to some value, but that's what caught my eye as a curiosity.. Just use the array and initialize them in a loop.
4  Using Arduino / Programming Questions / Re: Help with millis!!!! on: March 12, 2013, 03:12:45 pm
Pylon pointed out something, that makes me think the code might actually work like that if you moved the
"openedtime = millis();  // when did it open"
outside of the if and into the else branch.
Code:
  if ( digitalRead ( openedPin ) == HIGH )
  {
    digitalWrite ( LED1Pin, LOW );
    opentime = currenttime - openedtime;
  }
  else
  {
    openedtime = millis();  // when did it open
  }
However, it may be a little too late in the evening for me to think clearly.. Hmm, it's also a little scary that you don't initialize the unsigned long variables. So, it might be that you actually get LED2 to light up in some random cases when the program has just started. And the LED2 might be dimly lit in some case.
5  Using Arduino / Programming Questions / Re: How to Implements Quaternion in Attitude and heading reference system (AHRS)? on: March 12, 2013, 01:57:01 pm
I don't know much about AHRS, but I do roughly know what a quaternion is. I did study computer graphics and it was part of the math involved in 3D rotations. It's an alternative representation of orientation to Euler angle parametrization. Quaternions can be thought of as an extension to complex numbers. I think in this case you could represent the quaternion as q = q0 + q1 * i + q2 * j + q3 * k, but that would take me half a day to verify since I've forgotten all the math and I'm not sure it's that relevant. You can convert from one representation to another, like to roll, pitch and yaw angles if needed, but it's still safer to do rotation related math in quaternion space than in Euler space.

Anyways, it looks like you are supposed to read 3-coordinate data from a gyro, accelerometer and magnetometer, with whatever libraries you have, and feed that into the function. The function will spit out the quaternion elements into the global variables q0-q3, normalized. However, I would assume that you would need to initialize the components one way or another. Like, figuring out the initial attitude based on gravity element of the accelerometer, right?

Wherever you found that code at, does the same place not include any examples of a main function or anything that calls it? If not, find another implementation that does, and save time in figuring out how it's supposed to work.
6  Using Arduino / Programming Questions / Re: Printing Tri-dimensional Matrixes with triple for's on: March 10, 2013, 02:45:20 pm
Out of curiosity, does it work if you do something like this:
Code:
for(int i=0 ; i<8 ; i++){
    for(int j=0 ; j<5; j++){
      if(CharacterVector[0][i][j])
         Serial.print("1 ");
      else
         Serial.print("0 ");
    }
    Serial.print("\n");
  }
Trying to isolate this to either Serial or indexing/memory related issue.
7  Using Arduino / Programming Questions / Re: Keypad acting like a phone on: March 10, 2013, 02:35:02 pm
Well, I did actually use one of those land line phones with that funky rotating dial few decades ago. It didn't have a "call" button, that much I can remember...
8  Using Arduino / Programming Questions / Re: HEX Split on: March 10, 2013, 02:02:14 pm
I don't quite get this. I would assume that you are already sending the data as 8-bit characters. That's how your library most likely presents it anyways. I don't get where the number to string conversion comes in. Would be curious to see the code that you have for receiving and sending data.

If you now want to interpret the transmitted data from the hexadecimal representation into characters, then each "character" in that format represent 2 four-bit symbols, since it takes 4 bits to represent 16 values and hexadecimal happens to have 16 symbols. That's the easiest way of interpreting the hexadecimal representation to bits and back. You can take the high and low 4-bits to interpret what you have without the need for string to number and back to string conversions.

Then again, you could just as well be sending ASCII characters and interpret it as such unless you insist on saving that one half of a byte. So, ASCII character 1 could mark led 1, and so on, just to make it easy.

Edit: Oh, and you do realize that there is a difference between 'A' and 0xA? The first one is a character having a number value 65 in the ASCII character table and the latter is the hexadecimal (16-base) representation of the decimal (10-base) number 10.
9  Using Arduino / Programming Questions / Re: exp function speed on: March 10, 2013, 01:40:37 pm
Floats take 4 bytes each, so you would have an array that is half a kilobyte in size, right? Alright, if you have several similar arrays, it can be tight.

Low level hardware generally cannot do floating point math in hardware, so those kind of operations would be slow, no surprise there. If you need speed, you need to operate on integers until you really need to represent the floating point value somewhere, in my opinion. Or maybe there is a another cheap enough platform that can also do floating point math in hardware.
10  Using Arduino / Programming Questions / Re: avrdude: stk500_getsync(): not in sync: resp=0x00 on: March 10, 2013, 01:07:26 pm
almost every time I get this error it's because I have a fried the IC (atmega 328p)

Hi treebykooba, HOW do you manage this? You are obviously making BAD/WRONG connections. They donĀ“t get fried just by themselves so take some care and save some money.
Heh, I don't know about treebykooba, but I managed that once by connecting a 9V battery directly on the raw (<12V) input of a Pro Micro. These days, I connect a capacitor to avoid spikes when trying to power up the chip.. A switch might help too.
11  Using Arduino / Programming Questions / Re: switch case with keypad problem on: March 10, 2013, 11:50:46 am
You are printing the different character than you have the switch case statement on. What happens if you remove the second getKey call from inside the if statement (assuming the debouncing works)?
12  Using Arduino / Programming Questions / Re: Programming Style on: March 03, 2013, 06:00:03 am
This is my favourite

Refuctoring
The process of taking a well-designed piece of code and, through a series of small, reversible changes, making it completely unmaintainable by anyone except yourself.

_____
Rob
Yay, now I have a term to use for that. I've been seeing a lot of refuctoring at work lately maybe due to "small" spec changes along the way. Thanks a lot. I can use it in a sentence, "Let's not refuctor this again, mmkay?".
13  Using Arduino / Programming Questions / Re: send serial ONLY when sensors are touched? on: March 03, 2013, 05:51:09 am
I figured that at the receiving end you would have a loop with Serial.available()>n condition. So, at some point it would get to the waiting state and whenever it's raised from that state, the received data would always be in order. But if it's a continuous stream of data, I can see the problem.

My first thought was that you could use a synchronizing byte in the data sequence. Just send 0xFF or something to mark the start of the sequence. Then again, that might be only necessary at the start of the communication, think handshaking. You sync it at the beginning, and can then expect to receive the data in the correct order and save one byte per packet.

Edit: Heh, obviously, 0xFF as the synch wouldn't work if the rest of the data ever included that byte...
14  Using Arduino / Programming Questions / Re: Problem with my first sketch on: March 03, 2013, 05:30:53 am
Well, I don't have much hair either, but anyways. I bought one of those starters pack in January, and all the code seemed to have both setup and loop function, and they are also included in all the examples in Arduino IDE. I figured, ok, these function must already be called from somewhere. The Learning tab gives you the bareminimum example that is required for getting the code up and running. It also explains what the setup and loop are for.
http://arduino.cc/en/Tutorial/BareMinimum

I'm used to starting with examples before getting into the theoretical background, so I didn't find this a big problem. But if you start from the theoretical background, I guess this kind of stuff could be mentioned elsewhere too (where exactly does it need to be added?). As in, you don't need a main function of your own, since it's already there.

C code requires a main function as a starting point, and in Arduino environment it's found in main.cpp like this:
Code:
#include <Arduino.h>

int main(void)
{
init();

#if defined(USBCON)
USBDevice.attach();
#endif

setup();
   
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
       
return 0;
}
It calls setup(), and then loop() in an infinite for loop. This is always compiled into your sketch. You need to define setup and loop, but only once, because if you had multiple then the compiler wouldn't know which one to jump into and would report an error.

Ah, sorry, not relevant to this topic, but now I also see what that thing about serialEventRun was about. I didn't see that before.. must be because I just looked up the main function for the first time..
15  Using Arduino / Programming Questions / Re: Serial.begin confusion on: March 03, 2013, 04:55:18 am
In the most typical case, you'd want to write debug messages from your code and you can monitor it with serial monitor. Another case is communicating with other devices through the serial port(s).

If you don't set up the communication by calling Serial.begin from within setup() once, those messages could not be sent out. Serial.print etc just wouldn't work. You can call Serial.begin from elsewhere, but why would you, because it concerns initializing the serial port. Nick already gave you the documentation for what it does:
Code:
void setup() {
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
Pages: [1] 2 3 ... 6