Pages: [1]   Go Down
Author Topic: Need help with twitter-code!  (Read 650 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so i've just started with programming for arduino and since i've got a course in school where we are supposed to come up with a new product, i've started with the arduino because it seems to be the easiest way to build something new!
i'm in a group of real slackers and the only person who is currently working on this project is me, so my knowledge in coding is all we have...

what my project is supposed to do is to send me a tweet when a button is pressed (wireless doorbell and i've managed to get all the circuitry right, but it seems like i've failed with the coding.)

here's the code im currently using:
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x4F, 0x0D };
byte ip[] = { 192, 168, 0, 25 };
Twitter twitter("861799520-MhjIWEzWHz02OqvI8u5rByj83Js4OjpAcDpjR2g");
char msg[] = "you pressed the button!";
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin = 13;
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(buttonPin, INPUT);
   
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {       
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
 
  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    int status = twitter.wait();
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
   }
}

this is how it's all wired http://imgur.com/a/0XKvl (only temporarily)
what i want to know is, what am i doing wrong? since i have added the switch today, and tested so the button works by hooking up an LED to the wires (which originally were hooked up to a speaker since it's a wireless doorbell), im pretty sure the fault is in the code or to be more exact the part of the code which connects to the internet.
im going to check if the arduino gets the signal from the two wires (because that can be one problem) and does anyone know if i've made any mistakes regarding the code, because im almost a total noob when it comes to coding.

sources of some of the code:
the part which sends the tweet: http://arduino-tweet.appspot.com/
« Last Edit: October 05, 2012, 01:00:24 pm by Allther » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48566
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what i want to know is, what am i doing wrong?
You haven't told us what that code actually does. You haven't told us how that differs from what you expect. Yet, you want us to tell you why what the code does is different from what you expect, and how to fix it. I think that is not going to be possible.

Quote
since i have no switch connected yet (will add them tomorrow) i expect to get the tweet "No
If you have no switch connected, you should not be trying to read the state of the pin. Since you have not enabled the internal pullup resistor, with nothing connected the pin floats. It's state is not defined.

When you do connect the switch, don't forget the external pullup or pulldown resistors. Or, make life easy, use the internal pullup (digitalWrite(pin, HIGH); after the pinMode() call) and connect the switch to the pin and to ground.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i've tried to change the text so it maybe suits you, and i've also changed the code to the most recent version since i bumped into a few problems while adding the button.

the batteries (if that is interesting) is AA (1.5 Volts), and im currently wondering if i should change the HIGH in
Code:
if (buttonState == HIGH)
to a numeric value.

is it possible to use "smaller/greater than" signs (< >) instead of the two equal signs (==)?

i currently believe that the current is the problem(see what i did there?), thats why i want to know if i can use those signs!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48566
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the batteries (if that is interesting) is AA (1.5 Volts), and im currently wondering if i should change the HIGH in
Code:

if (buttonState == HIGH)

to a numeric value.
I don't understand what this is about. You are reading the state of a switch. That switch is a digital device. It is either pressed or it isn't. You can't press a switch part way. The switch pin will either be HIGH or LOW.

Quote
is it possible to use "smaller/greater than" signs (< >) instead of the two equal signs (==)?
Of course. Not that it makes any sense. If the state of the pin is not HIGH, it must be lower than that, or LOW. It can't be lower than LOW and it can't he higher than HIGH.

Quote
i currently believe that the current is the problem
How? If current is an issue, you aren't doing something right.
Logged

Pages: [1]   Go Up
Jump to: