I'm working on an indication lamp for a robotic arm.
i am using the BlinkM MaxM light. it comes with a library, and examples, i have modified the tester program so it has more tools, and i have a circuit board that interfaces the ISP line from A4 and A5, to the blinkm controller, and it works so i can control the light.
I am working on the code for my robot arm, and so far, all it does is it starts out not connected and disable, it chirps !BEEP! on the serial port of the programming baud of 115200, i reply !BOOP! in the serial monitor or later with a control program. i do this and it switches to connected mode.
now the issue is that i am using this light to indicate the status of this robot arm, blink red when not connected and not enable, i then reply and the robot will say !Contact!, after that is the command to tell the light to blink blue. i copied all the functions needed to control the light from the example. how ever, when it goes to switch the light from red to blue, it fails, not only does nothing happen, but my program freezes/crashes,
what debuging i did lead me to find that if i allow the program to loop where it keeps chirping every second(i use loop counting to delay the print so the arduino doesn't spam my port and cause a bad connection while also allowing the arduino to continue to run while it waits to chirp again) i have it chirp and check the buffer for the echo of !BEEP! this set the connected variable to true and stops the beeping, however i commented this out so i could see that it would say !Contact! and then continue to beep, but if the command to change the light color is there, the it fails to loop because it crashes there. so then removing the command allowed it to loop, proving that this was the issue.
this is odd because this command not only works in another program but it still works in this program. what i mean is, when the robot first turns on it resest the light to red, in the set up loop, and this command work fine in setup, but when ever called in the loop() loop, it crashes,
so i continued to find where it fail by checking the function, as seem below, the function uses the wire library to talk to the light, and that i placed it to print serial, how far it gets through the program, it end at the command
Wire.endTransmission();
that was the original command, i looked it up and learned that i could re write it to get stats of how it work, such as it returns an int value to indicate success or errors, as written below.
Any idea how come this command fails in the loop() when called while it works fine in the setup() and other sample programs, i have check that all the coding that is needed for it to work is a part of my program but i still get failure
this is the function
void BlinkM_playScript(byte addr, byte script_id, byte reps, byte pos)
{
Serial.print("Start talk, "); // i use this to debug where in the program that it crashes
Wire.beginTransmission(addr); // uses the wire library to communicate
Serial.print("Started, ");
Wire.write('p');
Wire.write(script_id);
Wire.write(reps);
Wire.write(pos);
Serial.println("Finished"); /// this is as far as the code gets
int num = Wire.endTransmission(false); // here is where id dies ![]()
Serial.print("Done talking! error stat: #"); // never gets printed because the code never reaches here
Serial.println(num);
}