Shop OBEX P1 Docs P2 Docs Learn Events
Javelin stamp and LISY300 communication — Parallax Forums

Javelin stamp and LISY300 communication

FreskFeskFreskFesk Posts: 3
edited 2012-03-27 16:38 in General Discussion
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:

[/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

  • RiJoRiRiJoRi Posts: 157
    edited 2012-03-16 07:26
    If you use the [ code ] and [ /code ] tags -- removing the spaces inside the brackets -- your code will be easier to read.

    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
    	dout=CPU.pin0;
    	sclk=CPU.pin1;
    	csn=CPU.pin2; 
    
    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
    	// assign aliases for pins
    	dout=CPU.pin0;
    	sclk=CPU.pin1;
    	csn=CPU.pin2;
    
    	// iniz 'value'
    	value=0;
    
    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??
  • FreskFeskFreskFesk Posts: 3
    edited 2012-03-21 04:13
    I get compiler error if I write for example "writePin(CPU.pin1, 1);".

    Thanks, though
  • Jon KeinathJon Keinath Posts: 146
    edited 2012-03-27 16:38
    FreskFesk wrote: »
    I get compiler error if I write for example "writePin(CPU.pin1, 1);".

    The proper syntax for the above statement would be:
    writePin(CPU.pin1, true);
    

    To assign a "name" to a pin use:
    final static int dataPin = CPU.pin1;
    

    --EDIT--

    You can then use the following statement:
    writePin(dataPin, true);
    
Sign In or Register to comment.