system
July 4, 2011, 11:29pm
1
Hi Guys,
I'm getting crazy..
The Blink-Example doesn't work: Either the led shines all the time or it is off.
But when I put
Serial.begin(9600);
in setup() it works.
Now I compile my sketches on my own (avr-gcc and send with avrdude) and the Blink-Example works.
I made a new sketch with my Wii-Nunchuk, so I have to use the Wire.h library.
Now my Serial-connection is buggy:
Serial.print("h"); // works
-----------------
Serial.println("h");
Serial.println("i"); // Doesn't work
------------------
Serial.print("h");Serial.print("h");Serial.print("h");Serial.print("h");Serial.print("h");
Serial.print("h");Serial.print("h");Serial.print("h");Serial.print("h"); // works
-----------------
Serial.print("h"); Serial.print("h");Serial.print("h");Serial.print("h");Serial.print("h");
Serial.print("h");Serial.print("h");Serial.print("h");Serial.print("h");Serial.print("h"); // doesn't work... (?)
Doesn't work means, that the programm won't start (my LEDs don't shine) and there's no serial connection (blinking light).
I use the Arduino Uno and my distro is Gentoo
Any ideas?
Thanks for your help!
cmiyc
July 4, 2011, 11:47pm
2
Use "code" not "quote" to post code.
For the best results, post the entire code you are using that does and doesn't work. Snippets are difficult (to impossible) to debug.
system
July 5, 2011, 12:03am
3
#include <Wire.h>
struct nunchuk {
byte id;
byte joy_x, joy_y;
int accu_x, accu_y, accu_z;
bool z, c;
};
struct nunchuk *nun;
void nun_update(){
byte h;
Wire.requestFrom(0x52, 6);
for( int i=0; i<6 && Wire.available(); i++) {
h = (Wire.receive() ^ 0x17) + 0x17; // magic..
if( i == 0 ) nun->joy_x = h;
if( i == 1 ) nun->joy_y = h;
if( i == 2 ) nun->accu_x = h << 2;
if( i == 3 ) nun->accu_y = h << 2;
if( i == 4 ) nun->accu_z = h << 2;
if( i == 5 ) {
nun->accu_x |= (h >> 2)&3;
nun->accu_y |= (h >> 4)&3;
nun->accu_z |= (h >> 6);
h&1 ? nun->z = true : nun->z = false;
h&3 ? nun->c = true : nun->c = false;
}
}
Wire.beginTransmission(0x52);
Wire.send(0x00);
Wire.endTransmission();
}
void nun_init(byte id, struct nunchuk *nun){
nun->id=id;
Wire.begin();
Wire.beginTransmission(id);
Wire.send(0x40);
Wire.send(0x00);
Wire.endTransmission();
}
void setup(){
Serial.begin(9600);
nun = (struct nunchuk *) malloc(sizeof(struct nunchuk));
nun_init(0x52,nun);
}
void loop() {
nun_update();
Serial.print("x:"); Serial.print(nun->accu_x);
Serial.print(" y:"); Serial.print(nun->accu_y);
Serial.print(" z:"); Serial.print(nun->accu_z);
Serial.print(" b_c:"); nun->c ? Serial.print("X") : Serial.print("_");
Serial.print(" b_z:"); nun->z ? Serial.print("X") : Serial.print("_");
Serial.print(" j_x:"); Serial.print(nun->joy_x);
Serial.print(" j_y:"); Serial.print(nun->joy_y);
delay(100);
}
-- doesn't work
void loop() {
nun_update();
Serial.print("x:"); Serial.print(nun->accu_x);
delay(100);
}
-- works
Without nun_update() and nun_init() it works too...
/* Edited, forgot to malloc space */
Two things...
This is the wrong section of the forum for this sort of question.
nun is an uninitialized pointer which is always trouble. While not a good solution, the following changes should make the sketch more stable...
struct nunchuk nunstorage;
void setup( void )
{
nun = &nunstorage;
system
July 5, 2011, 12:41am
5
I just changed something and forgot to malloc space.
Why is this the wrong section? Where should I go?
Why is this the wrong section?
Installation & Troubleshooting
For problems with Arduino itself, NOT your project
Where should I go?
http://arduino.cc/forum/index.php/board,4.0.html
Read my post..
The Blink example doesn't work.
And I have problems with my Serial connection.
This is not about my project.
apfelmann:
This is not about my project
#include struct nunchuk { byte id; byte joy_x, joy_y; int accu_x, accu_y, accu_z; bool z, c; }; struct nunchuk *nun; void nun_update(){ byte h; Wire.requestFrom(0x52, 6); for( int i=0; i<6 && Wire.available(); i++) { h =...
...I cannot find that code in any of the examples so I assumed it was your code. Which example are you using?
You'll find the Blink example in 1.Basic->Blink
#include struct nunchuk { byte id; byte joy_x, joy_y; int accu_x, accu_y, accu_z; bool z, c; }; struct nunchuk *nun; void nun_update(){ byte h; Wire.requestFrom(0x52, 6); for( int i=0; i<6 && Wire.available(); i++) { h =...
-- is my code.
BUT I ment I don't want to debug my Code. James C4S wanted to see my code and I gave it to him.
I initialized a Wire with no funktions. And my serial connect didn't work.
Blink doesn't work without serial connection in setup().
I think this is troubleshooting.
I'm sorry for missunderstandings, but I don't post often in forums
By the way my english is very bad, I think.
cmiyc
July 5, 2011, 7:57pm
10
I think I understand what you are asking.
Are you saying this code:
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
Does not blink pin 13 unless you change setup() to say:
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
?
system
July 5, 2011, 8:05pm
12
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
The LED shines all the time..
But this one works too..
void setup() {
pinMode(13, OUTPUT);
}
int i = 0;
void loop() {
i++;
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
cmiyc
July 5, 2011, 8:11pm
13
Ahhh... Sounds like delay() is broken, which was a known issue.
What version of the Arduino IDE are you using?
You might be interested in the last couple of posts on this thread. A couple of posts on updating avr-gcc and binutils to get Gentoo working.
http://arduino.cc/forum/index.php/topic,49900.15.html