Editing Hack Notes CVA 090324

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
----
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
----
=[http://abigumydive.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
----
=[http://abigumydive.co.cc CLICK HERE]=
----
</div>
=Compass Vibro-Anklet Hacking Session 2009.03.24=
=Compass Vibro-Anklet Hacking Session 2009.03.24=


Line 10: Line 18:
*Attached leads to a pager motor for bread-boarding.
*Attached leads to a pager motor for bread-boarding.
[[Image:Anklethack-1.jpg]]
[[Image:Anklethack-1.jpg]]
*Set up circuit with a "safety" diode, not sure why.
*Set up circuit with a &quot;safety&quot; diode, not sure why.
[[Image:Anklethack-2.jpg]]
[[Image:Anklethack-2.jpg]]
*The transistor seems to be working inverse-proportionally to the pwm voltage from the Arduino. Is that normal? We don't know.
*The transistor seems to be working inverse-proportionally to the pwm voltage from the Arduino. Is that normal? We don't know.


==The Code==
==The Code==
*Important: "On newer Arduino boards (including the Mini and BT) with the ATmega168 chip, this function works on pins 3, 5, 6, 9, 10, and 11. Older USB and serial Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11."
*Important: &quot;On newer Arduino boards (including the Mini and BT) with the ATmega168 chip, this function works on pins 3, 5, 6, 9, 10, and 11. Older USB and serial Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.&quot;
*Given that analogWrite() takes a value 0-255 and that compass_angle is a value from -180 to 180. We thought:
*Given that analogWrite() takes a value 0-255 and that compass_angle is a value from -180 to 180. We thought:
**vibro_strength = (255 - abs(compass_angle) * (255/180))
**vibro_strength = (255 - abs(compass_angle) * (255/180))
Line 22: Line 30:
*Of course this has East and West not instanteneously distinguishable from the pager motor speed.
*Of course this has East and West not instanteneously distinguishable from the pager motor speed.


<pre>
&lt;pre&gt;
/*
/*
Some Htachi HM55B Compass reading code copied from: kiilo kiilo@kiilo.org
Some Htachi HM55B Compass reading code copied from: kiilo kiilo@kiilo.org
Line 28: Line 36:
*/
*/


#include <LCD4Bit.h> // module for lcd
#include &lt;LCD4Bit.h&gt; // module for lcd
#include <math.h> //
#include &lt;math.h&gt; //
#include <stdio.h>
#include &lt;stdio.h&gt;




Line 55: Line 63:


void ShiftOut(int Value, int BitsCount) {
void ShiftOut(int Value, int BitsCount) {
   for(int i = BitsCount; i >= 0; i--) {
   for(int i = BitsCount; i &gt;= 0; i--) {
     digitalWrite(CLK_pin, LOW);
     digitalWrite(CLK_pin, LOW);
     if ((Value >> i) & 1) {
     if ((Value &gt;&gt; i) &amp; 1) {
       digitalWrite(DIO_pin, HIGH);
       digitalWrite(DIO_pin, HIGH);
       //Serial.print("1");
       //Serial.print(&quot;1&quot;);
     }
     }
     else {
     else {
       digitalWrite(DIO_pin, LOW);
       digitalWrite(DIO_pin, LOW);
       //Serial.print("0");
       //Serial.print(&quot;0&quot;);
     }
     }
     digitalWrite(CLK_pin, HIGH);
     digitalWrite(CLK_pin, HIGH);
     delayMicroseconds(1);
     delayMicroseconds(1);
   }
   }
//Serial.print(" ");
//Serial.print(&quot; &quot;);
}
}


Line 75: Line 83:
     ShiftIn_result = 0;
     ShiftIn_result = 0;
     pinMode(DIO_pin, INPUT);
     pinMode(DIO_pin, INPUT);
     for(int i = BitsCount; i >= 0; i--) {
     for(int i = BitsCount; i &gt;= 0; i--) {
       digitalWrite(CLK_pin, HIGH);
       digitalWrite(CLK_pin, HIGH);
       delayMicroseconds(1);
       delayMicroseconds(1);
       if (digitalRead(DIO_pin) == HIGH) {
       if (digitalRead(DIO_pin) == HIGH) {
         ShiftIn_result = (ShiftIn_result << 1) + 1;  
         ShiftIn_result = (ShiftIn_result &lt;&lt; 1) + 1;  
         //Serial.print("x");
         //Serial.print(&quot;x&quot;);
       }
       }
       else {
       else {
         ShiftIn_result = (ShiftIn_result << 1) + 0;
         ShiftIn_result = (ShiftIn_result &lt;&lt; 1) + 0;
         //Serial.print("_");
         //Serial.print(&quot;_&quot;);
       }
       }
       digitalWrite(CLK_pin, LOW);
       digitalWrite(CLK_pin, LOW);
       delayMicroseconds(1);
       delayMicroseconds(1);
     }
     }
   //Serial.print(":");
   //Serial.print(&quot;:&quot;);


// below is difficult to understand:
// below is difficult to understand:
Line 97: Line 105:
// the integer.
// the integer.
// see: http://en.wikipedia.org/wiki/Two%27s_complement
// see: http://en.wikipedia.org/wiki/Two%27s_complement
   if ((ShiftIn_result >> 11) & 1) {
   if ((ShiftIn_result &gt;&gt; 11) &amp; 1) {
     ShiftIn_result = (B11111000 << 8) | ShiftIn_result;  
     ShiftIn_result = (B11111000 &lt;&lt; 8) | ShiftIn_result;  
   }
   }


Line 142: Line 150:


void loop() {
void loop() {
   if (millis() - serialTimer > 50 ) {
   if (millis() - serialTimer &gt; 50 ) {


   //read compass and print data to lcd and serial out
   //read compass and print data to lcd and serial out
Line 150: Line 158:
   status = HM55B_ReadCommand();
   status = HM55B_ReadCommand();
   Serial.print(status); // read data and print Status
   Serial.print(status); // read data and print Status
   sprintf(string, "%2d", status);
   sprintf(string, &quot;%2d&quot;, status);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.print(" ");
   Serial.print(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
   X_Data = ShiftIn(11); // Field strength in X
   X_Data = ShiftIn(11); // Field strength in X
   Y_Data = ShiftIn(11); // and Y direction
   Y_Data = ShiftIn(11); // and Y direction
   Serial.print(X_Data); // print X strength
   Serial.print(X_Data); // print X strength
   sprintf(string, "%3d", X_Data);
   sprintf(string, &quot;%3d&quot;, X_Data);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.print(" ");
   Serial.print(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
   Serial.print(Y_Data); // print Y strength
   Serial.print(Y_Data); // print Y strength
   sprintf(string, "%3d", Y_Data);
   sprintf(string, &quot;%3d&quot;, Y_Data);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.print(" ");
   Serial.print(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
   digitalWrite(EN_pin, HIGH); // ok deselect chip
   digitalWrite(EN_pin, HIGH); // ok deselect chip
   angle = 180 * (atan2(-Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!!
   angle = 180 * (atan2(-Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!!
   Serial.print(angle); // print angle
   Serial.print(angle); // print angle
   sprintf(string, "%4d", angle);
   sprintf(string, &quot;%4d&quot;, angle);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.println(" ");
   Serial.println(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
    
    
   //control motors
   //control motors
Line 179: Line 187:
   analogWrite(VIB1_pin, int(vibro_strength));
   analogWrite(VIB1_pin, int(vibro_strength));
   lcd.cursorTo(1,0);
   lcd.cursorTo(1,0);
   lcd.printIn("V1=");
   lcd.printIn(&quot;V1=&quot;);
   sprintf(string, "%3d", int(vibro_strength));
   sprintf(string, &quot;%3d&quot;, int(vibro_strength));
   lcd.printIn(string);
   lcd.printIn(string);
    
    
Line 186: Line 194:
   pinMode(VIB2_pin, OUTPUT);
   pinMode(VIB2_pin, OUTPUT);
   analogWrite(VIB2_pin, int(vibro_strength));
   analogWrite(VIB2_pin, int(vibro_strength));
   lcd.printIn(" V2=");
   lcd.printIn(&quot; V2=&quot;);
   sprintf(string, "%3d", int(vibro_strength));
   sprintf(string, &quot;%3d&quot;, int(vibro_strength));
   lcd.printIn(string);
   lcd.printIn(string);
   }
   }
}
}
</pre>
&lt;/pre&gt;


==Basic Armature==
==Basic Armature==
*We decided that we will just use a long strip of 2"-wide sew-on velcro as the components can just be sandwiched in between the opposite sides of the velcro, which can then be offset to allow for stick to itself after wrapping around the ankle.
*We decided that we will just use a long strip of 2&quot;-wide sew-on velcro as the components can just be sandwiched in between the opposite sides of the velcro, which can then be offset to allow for stick to itself after wrapping around the ankle.
[[Image:Anklethack-4.jpg]]
[[Image:Anklethack-4.jpg]]
*We decided to only cut half the overlapping bit to still give somewhere to sandwich electronics on the section of the band that sticks to itself after wrapping.
*We decided to only cut half the overlapping bit to still give somewhere to sandwich electronics on the section of the band that sticks to itself after wrapping.
Line 222: Line 230:
*#The behavior of the pager motors are not equal and as a pair are not acting as expected.
*#The behavior of the pager motors are not equal and as a pair are not acting as expected.
*#Whoah something is crazy wrong with our circuits!
*#Whoah something is crazy wrong with our circuits!
*#Hooray! Turns out the little bin labeled "2N2222" transistors actually has 2N2222's in the front, but other, almost visually identical transistors in the back. We had one of each. / "Oh look, there are actually two labels!" / "BLAST!"
*#Hooray! Turns out the little bin labeled &quot;2N2222&quot; transistors actually has 2N2222's in the front, but other, almost visually identical transistors in the back. We had one of each. / &quot;Oh look, there are actually two labels!&quot; / &quot;BLAST!&quot;
*Dang. Now the two pager motors are clearly differentiable.
*Dang. Now the two pager motors are clearly differentiable.
**The Moral: Always debug your circuits and learn to read labels.
**The Moral: Always debug your circuits and learn to read labels.
Line 237: Line 245:
Pulse width table:
Pulse width table:


{| border="1" cellspacing="0" cellpadding="5" align="center"
{| border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot; align=&quot;center&quot;
|-
|-
! Direction
! Direction
Line 257: Line 265:


Key:
Key:
"!" is the initial 100ms pulse, "-" is 200ms off, and "X" is 200ms on. Each interval lasts 2100ms followed (I think) by another 100ms gap.
&quot;!&quot; is the initial 100ms pulse, &quot;-&quot; is 200ms off, and &quot;X&quot; is 200ms on. Each interval lasts 2100ms followed (I think) by another 100ms gap.


* This seems fairly intuitive on the ankle, and easier to tell direction than the strength modulation of Round 2.  It also works almost as well with _just one motor_ going.  
* This seems fairly intuitive on the ankle, and easier to tell direction than the strength modulation of Round 2.  It also works almost as well with _just one motor_ going.  
Line 264: Line 272:


==The New Code==
==The New Code==
<pre>
&lt;pre&gt;
/*
/*
Some Hitachi HM55B Compass reading code copied from: kiilo kiilo@kiilo.org
Some Hitachi HM55B Compass reading code copied from: kiilo kiilo@kiilo.org
Line 270: Line 278:
*/
*/


#include <LCD4Bit.h> // module for lcd
#include &lt;LCD4Bit.h&gt; // module for lcd
#include <math.h> //
#include &lt;math.h&gt; //
#include <stdio.h>
#include &lt;stdio.h&gt;




Line 298: Line 306:


void ShiftOut(int Value, int BitsCount) {
void ShiftOut(int Value, int BitsCount) {
   for(int i = BitsCount; i >= 0; i--) {
   for(int i = BitsCount; i &gt;= 0; i--) {
     digitalWrite(CLK_pin, LOW);
     digitalWrite(CLK_pin, LOW);
     if ((Value >> i) & 1) {
     if ((Value &gt;&gt; i) &amp; 1) {
       digitalWrite(DIO_pin, HIGH);
       digitalWrite(DIO_pin, HIGH);
       //Serial.print("1");
       //Serial.print(&quot;1&quot;);
     }
     }
     else {
     else {
       digitalWrite(DIO_pin, LOW);
       digitalWrite(DIO_pin, LOW);
       //Serial.print("0");
       //Serial.print(&quot;0&quot;);
     }
     }
     digitalWrite(CLK_pin, HIGH);
     digitalWrite(CLK_pin, HIGH);
     delayMicroseconds(1);
     delayMicroseconds(1);
   }
   }
//Serial.print(" ");
//Serial.print(&quot; &quot;);
}
}


Line 318: Line 326:
     ShiftIn_result = 0;
     ShiftIn_result = 0;
     pinMode(DIO_pin, INPUT);
     pinMode(DIO_pin, INPUT);
     for(int i = BitsCount; i >= 0; i--) {
     for(int i = BitsCount; i &gt;= 0; i--) {
       digitalWrite(CLK_pin, HIGH);
       digitalWrite(CLK_pin, HIGH);
       delayMicroseconds(1);
       delayMicroseconds(1);
       if (digitalRead(DIO_pin) == HIGH) {
       if (digitalRead(DIO_pin) == HIGH) {
         ShiftIn_result = (ShiftIn_result << 1) + 1;  
         ShiftIn_result = (ShiftIn_result &lt;&lt; 1) + 1;  
         //Serial.print("x");
         //Serial.print(&quot;x&quot;);
       }
       }
       else {
       else {
         ShiftIn_result = (ShiftIn_result << 1) + 0;
         ShiftIn_result = (ShiftIn_result &lt;&lt; 1) + 0;
         //Serial.print("_");
         //Serial.print(&quot;_&quot;);
       }
       }
       digitalWrite(CLK_pin, LOW);
       digitalWrite(CLK_pin, LOW);
       delayMicroseconds(1);
       delayMicroseconds(1);
     }
     }
   //Serial.print(":");
   //Serial.print(&quot;:&quot;);


// below is difficult to understand:
// below is difficult to understand:
Line 340: Line 348:
// the integer.
// the integer.
// see: http://en.wikipedia.org/wiki/Two%27s_complement
// see: http://en.wikipedia.org/wiki/Two%27s_complement
   if ((ShiftIn_result >> 11) & 1) {
   if ((ShiftIn_result &gt;&gt; 11) &amp; 1) {
     ShiftIn_result = (B11111000 << 8) | ShiftIn_result;  
     ShiftIn_result = (B11111000 &lt;&lt; 8) | ShiftIn_result;  
   }
   }


Line 385: Line 393:


void loop() {
void loop() {
   if (millis() - serialTimer > 2200 ) {
   if (millis() - serialTimer &gt; 2200 ) {


   //read compass and print data to lcd and serial out
   //read compass and print data to lcd and serial out
Line 393: Line 401:
   status = HM55B_ReadCommand();
   status = HM55B_ReadCommand();
   Serial.print(status); // read data and print Status
   Serial.print(status); // read data and print Status
   sprintf(string, "%2d", status);
   sprintf(string, &quot;%2d&quot;, status);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.print(" ");
   Serial.print(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
   X_Data = ShiftIn(11); // Field strength in X
   X_Data = ShiftIn(11); // Field strength in X
   Y_Data = ShiftIn(11); // and Y direction
   Y_Data = ShiftIn(11); // and Y direction
   Serial.print(X_Data); // print X strength
   Serial.print(X_Data); // print X strength
   sprintf(string, "%3d", X_Data);
   sprintf(string, &quot;%3d&quot;, X_Data);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.print(" ");
   Serial.print(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
   Serial.print(Y_Data); // print Y strength
   Serial.print(Y_Data); // print Y strength
   sprintf(string, "%3d", Y_Data);
   sprintf(string, &quot;%3d&quot;, Y_Data);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.print(" ");
   Serial.print(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
   digitalWrite(EN_pin, HIGH); // ok deselect chip
   digitalWrite(EN_pin, HIGH); // ok deselect chip
   angle = 180 * (atan2(-Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!!
   angle = 180 * (atan2(-Y_Data , X_Data) / M_PI); // angle is atan( -y/x) !!!
   Serial.print(angle); // print angle
   Serial.print(angle); // print angle
   sprintf(string, "%4d", angle);
   sprintf(string, &quot;%4d&quot;, angle);
   lcd.printIn(string);
   lcd.printIn(string);
   Serial.println(" ");
   Serial.println(&quot; &quot;);
   lcd.printIn(" ");
   lcd.printIn(&quot; &quot;);
    
    
   // control motors with new pulse scheme
   // control motors with new pulse scheme
Line 422: Line 430:
   pulse_length = (angle*2000.0/180.0);
   pulse_length = (angle*2000.0/180.0);
   lcd.cursorTo(1,0);
   lcd.cursorTo(1,0);
   lcd.printIn(" PuLn=");
   lcd.printIn(&quot; PuLn=&quot;);
   sprintf(string, "%4d    ", int(pulse_length));
   sprintf(string, &quot;%4d    &quot;, int(pulse_length));
   lcd.printIn(string);
   lcd.printIn(string);
   pinMode(VIB1_pin, OUTPUT);
   pinMode(VIB1_pin, OUTPUT);
Line 430: Line 438:
   analogWrite(VIB2_pin, 255);
   analogWrite(VIB2_pin, 255);
   delay(100);
   delay(100);
   if (pulse_length > 0)
   if (pulse_length &gt; 0)
   {
   {
     analogWrite(VIB1_pin, 215);
     analogWrite(VIB1_pin, 215);
Line 452: Line 460:
   }
   }
}
}
</pre>
&lt;/pre&gt;


==Plans for Next Hacking Session==
==Plans for Next Hacking Session==
Line 460: Line 468:


==Stuff that would have been nice to have==
==Stuff that would have been nice to have==
*"Third hand" for holding stuff while soldering.
*&quot;Third hand&quot; for holding stuff while soldering.
*Our RBBBs already! That's why we [[RBBB_ORDER_SIGN_UP|ordered them today]].
*Our RBBBs already! That's why we [[RBBB_ORDER_SIGN_UP|ordered them today]].


[[Category:Sensebridge]]
[[Category:Sensebridge]]
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Noisebridge:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)