Javelin stamp and LISY300 communication
FreskFesk
Posts: 3
Hi all,
I've encountered a problem with my javelin. My javelin and my gyro (lisy300) won't communicate properly. I do get signals which vary as a gyro should, but they aren't correct. I've connected all wires like on the example code on the BS2. Here is my code:
I think there is a problem with the trailing zeroes or something like that.
Example of output is:
0
0
0
0
3
0
0
0
0
0
0
6
0
0
3
3
0
Thank for reading my post, all replies are welcome!
I've encountered a problem with my javelin. My javelin and my gyro (lisy300) won't communicate properly. I do get signals which vary as a gyro should, but they aren't correct. I've connected all wires like on the example code on the BS2. Here is my code:
[/COLOR][SIZE=2][COLOR=#333333] [/COLOR][/SIZE][SIZE=2][COLOR=#333333]import stamp.core.*;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333]import stamp.math.*;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] [/COLOR][/SIZE] [SIZE=2][COLOR=#333333] [/COLOR][/SIZE] [SIZE=2][COLOR=#333333]class gyrotest{[/COLOR][/SIZE] [SIZE=2][COLOR=#333333][/COLOR][/SIZE] [SIZE=2][COLOR=#333333] static int dout;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] static int sclk;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] static int csn; [/COLOR][/SIZE] [SIZE=2][COLOR=#333333] static int value; [/COLOR][/SIZE] [SIZE=2][COLOR=#333333] public static void main() {[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] dout=CPU.pin0;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] sclk=CPU.pin1;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] csn=CPU.pin2;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] value=0;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] [/COLOR][/SIZE] [SIZE=2][COLOR=#333333] CPU.writePin(csn,true);[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] CPU.writePin(sclk,false);[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] CPU.delay(500);[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] [/COLOR][/SIZE] [SIZE=2][COLOR=#333333] value=readGyro();[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] while(true){[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] value=readGyro();[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] System.out.println(value);[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] CPU.delay(50);[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] }[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] }[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] [/COLOR][/SIZE] [SIZE=2][COLOR=#333333] public static int readGyro(){ [/COLOR][/SIZE] [COLOR=#333333]CPU.writePin(csn,false);[/COLOR] [SIZE=2][COLOR=#333333] int x=CPU.shiftIn(dout,sclk,13,CPU.POST_CLOCK_MSB);[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] CPU.writePin(csn,true);[/COLOR][/SIZE] [SIZE=2][COLOR=#333333][/COLOR][/SIZE] [SIZE=2][COLOR=#333333] return x;[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] }[/COLOR][/SIZE] [SIZE=2][COLOR=#333333]}[/COLOR][/SIZE] [SIZE=2][COLOR=#333333] [/COLOR][/SIZE] [COLOR=#333333]
I think there is a problem with the trailing zeroes or something like that.
Example of output is:
0
0
0
0
3
0
0
0
0
0
0
6
0
0
3
3
0
Thank for reading my post, all replies are welcome!
Comments
Also, using the bit value 0 or 1 to write to pins is a lot safer than using true and false. There are languages that use 0 for true!
Finally, I'm a C programmer, and sure looks as if you are assigning the values of the 3 pins to the three variables.
Finally, using comments is EXTREMELY IMPORTANT for debugging. If your code read it would help not only you, but the readers of your code. Yeah, I know that programming courses do NOT use comments in their code snippets, but consider that the text around the code snippet is a HUGE comment!
HTH,
--Rich
P.S., what does "forst=value;" do??
Thanks, though
The proper syntax for the above statement would be:
To assign a "name" to a pin use:
--EDIT--
You can then use the following statement: