Pages: [1]   Go Down
Author Topic: Accelerometer data to processing (skateboarding project)  (Read 560 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Everybody!

Im trying to create a wireless device that can tell when a skateboard ollies.

Im using an arduino pro mini with and accelerometer and bluetooth. i have an arduino file that listens to my accelerometer and has a few if statements that create a serial print in when the board/accelerometer move vertically. this is all done wirelessly using blue tooth. works great.

I also have a processing file that creates a twitter post when the mouse is clicked.

What i would like to do is create a twitter post when the board move vertically instead of clicking the mouse.

so, what i think needs to happen is, have the processing file recognize the if statements...?

how do i go about linking or combining these files together?

Here is my arduino code.
Code:
/*
 ADXL3xx
 
 Reads an Analog Devices ADXL3xx accelerometer and communicates the
 acceleration to the computer.  The pins used are designed to be easily
 compatible with the breakout boards from Sparkfun, available from:
 http://www.sparkfun.com/commerce/categories.php?c=80

 http://www.arduino.cc/en/Tutorial/ADXL3xx

 The circuit:
 analog 0: accelerometer self test
 analog 1: z-axis
 analog 2: y-axis
 analog 3: x-axis
 analog 4: ground
 analog 5: vcc
 
 created 2 Jul 2008
 by David A. Mellis
 modified 4 Sep 2010
 by Tom Igoe
 
 This example code is in the public domain.

*/

// these constants describe the pins. They won't change:
const int groundpin = 2;             // analog input pin 2 -- ground
const int powerpin = 4;              // analog input pin 4 -- voltage
const int zpin = A2;                  // z-axis of the accelerometer
const int ypin = A1;                  // y-axis
const int xpin = A0;                  // x-axis (only on 3-axis models)
int sensorValue;
void setup()
{
  // initialize the serial communications:
  Serial.begin(115200);
 
  // Provide ground and power by using the analog inputs as normal
  // digital pins.  This makes it possible to directly connect the
  // breakout board to the Arduino.  If you use the normal 5V and
  // GND pins on the Arduino, you can remove these lines.

}

void loop()
{
  // print the sensor values:
  Serial.print(analogRead(xpin));
  // print a tab between values:
 
    if(analogRead(xpin)<495)
   Serial.println("Pop Shove-it");
   
   if(analogRead(ypin)>495)
   Serial.println("None");
 
  Serial.print("\t");
  Serial.print(analogRead(ypin));
 
  if(analogRead(ypin)<475)
   Serial.println("Kickflip");
   
   if(analogRead(ypin)>475)
   Serial.println("None");
 
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(zpin));
 
  if(analogRead(zpin)>600)
   Serial.println("Ollie");
 
   if(analogRead(zpin)<600)
   Serial.println("None");
 
  Serial.println();
  // delay before next reading:
  delay(100);
}

Here is the processing code.

Code:

/*
Posts a message to a Twitter account when you press the mouse button.
Uses Twitter4j, http://twitter4j.org.
For more info: http://tinkerlondon.com/now/2010/09/13/oauth-twitter-and-processing/
Daniel Soltis, September 2010
*/

import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;

String msg = "Ollie";

//copy and paste these from your application in dev.twitter.com
String consumer_key = "cv50u99znWOAOnOEUkhDA";
String consumer_secret = "dzVnD4nLzQd9FAUg47AyEVJKPQgY6ey6dsdOZDsj2FY";
String oauth_token = "276648172-s7m9Z4BPDlREyGJkllFKu84lguDeWkJU4ZKm6Y9E";
String oauth_token_secret = "zKN1i9SGNeh6PDjrEmv8BzeAYrErRac3Mjfs9XjU";

color bgcolor = color(255);
long timer;

void setup() {
size(640,480);
}

void draw() {
background(bgcolor);
if (millis()-timer > 2000) bgcolor = color(255);
}

void mousePressed() {
Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance (
consumer_key, consumer_secret,
new AccessToken( oauth_token, oauth_token_secret) );
try {
Status st = twitter.updateStatus(msg + " "  + second());
println("Successfully updated the status to [" + st.getText() + "].");
bgcolor = color(0,0,255);
timer = millis();
}
catch (TwitterException e) {
println(e.getStatusCode());
}
}



Please help, Thanks.

Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have connected my accelerometer and the processing file BUT because the accelerometer always has a read of around 550 it is posting a new tweet every second or however long the delay is i think (100) millis

i've tried


Code:

/*
Posts a message to a Twitter account when you press the mouse button.
Uses Twitter4j, http://twitter4j.org.
For more info: http://tinkerlondon.com/now/2010/09/13/oauth-twitter-and-processing/
Daniel Soltis, September 2010
*/

import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;

import processing.serial.*; //new

String msg = "Ollie"; //my tweet

//copy and paste these from your application in dev.twitter.com
String consumer_key = "cv50u99znWOAOnOEUkhDA";
String consumer_secret = "dzVnD4nLzQd9FAUg47AyEVJKPQgY6ey6dsdOZDsj2FY";
String oauth_token = "276648172-s7m9Z4BPDlREyGJkllFKu84lguDeWkJU4ZKm6Y9E";
String oauth_token_secret = "zKN1i9SGNeh6PDjrEmv8BzeAYrErRac3Mjfs9XjU";

color bgcolor = color(255);
long timer;
 Serial myPort;        // The serial port
 
void setup() {
size(640,480);

//new below
 // List all the available serial ports
 println(Serial.list());
 // I know that the first port in the serial list on my mac
 // is always my  Arduino, so I open Serial.list()[0].
 // Open whatever port is the one you're using.
 myPort = new Serial(this, Serial.list()[0], 9600);
 // don't generate a serialEvent() unless you get a newline character:
 myPort.bufferUntil('\n');
 //new above

}

void draw() {
background(bgcolor);
if (millis()-timer > 2000) bgcolor = color(255);
}

void serialEvent (Serial myPort) {
 
Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance (
consumer_key, consumer_secret,
new AccessToken( oauth_token, oauth_token_secret) );
try {
Status st = twitter.updateStatus(msg + " "  + second());
println("Successfully updated the status to [" + st.getText() + "].");
bgcolor = color(0,0,255);
timer = millis();
}
catch (TwitterException e) {
println(e.getStatusCode());
}
}
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

here is what i have narrowed it down to.

I have arduino sketch that registers vertical lift and prints "Ollie" into the serial monitor.

I have a processing sketch that posts "Ollie" on twitter when i press the mouse.

I have a processing sketch that posts "Ollie" on twitter when it registers data from the arduino, which is every 100millis, therefore every 100 millis it posts Ollie on twitter.

what i need to figure out is; how to have any data lower that 550 be classified as null to processing. i need the accelerometer to act as a button in processing.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Again.


I need to figure out what to replace mousePressed() with. so instead of mousePressed() it would be accelerometer data >550.
Logged

Pages: [1]   Go Up
Jump to: