Show Posts
Pages: 1 ... 5 6 [7] 8 9
91  Using Arduino / Project Guidance / Re: Reading Tweets and Tweeting with Ethernet on: September 01, 2012, 02:53:08 pm
Quick question. Currently when I run my code I tap the button and it sends all of the tweets in one shot (every time it loops. How do I make it only send one tweet each time the button is pressed?

I think the problem is here...
Code:
for (int i = 0; i < 4; i++){
         if (twitter.post(buttonPressed[i]))


full code
Code:
#include <Twitter.h>
#include <SPI.h>
#include <Ethernet.h>

// Ethernet Shield Settings
byte mac[] = { blahblahblahblahblah };

// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { blahblahblahblahblah };

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("blahblahblahblahblahblahblah");


//which pins are used as INPUT/OUTPUT
const int buttonPin = 2;
const int ledPin = 13;

//Set the buttons state to 0 to start
int buttonState = 0;

// Messages to post
char* buttonPressed[] = {"please work"," come on, please!", "I hope it works", "come on you swine!"};



void setup ()
{
  delay(1000);
  Ethernet.begin(mac);
  Serial.begin(9600);
  Serial.println("connecting ...");
 
 
  //what the pins are used as
  pinMode (ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}


void loop()
{
  //buttonState is the reading from the input buttonPin
  buttonState = digitalRead(buttonPin);
 
  //if the button is pressed, 
  if (buttonState ==HIGH){
         //turn the light on
         digitalWrite(ledPin, HIGH);
         
         //and tweet
         Serial.println("button pressed");
         for (int i = 0; i < 4; i++){
         if (twitter.post(buttonPressed[i])) {
           int status = twitter.wait();
           if (status ==200){
             Serial.println("Tweeted!");
           } else {
             Serial.print("failed : code ");
             Serial.println(status);
           }
         }else {
           Serial.println("connection failed");
         }
    }
  }
    else{
    }
  } 
92  Using Arduino / Sensors / Re: Interfacing to Miltone eTape on: September 01, 2012, 06:52:31 am
How did it go?

I've just got some eTape to do the same thing.
93  Using Arduino / Project Guidance / Re: Stuck on pcb design layout on: September 01, 2012, 05:16:39 am
Could you use Fritzing for that?

Just to get a rough layout for your Eagle designs?
94  Using Arduino / Project Guidance / Reading Tweets and Tweeting with Ethernet on: September 01, 2012, 05:03:32 am
Hi,
I've seen projects where people tweet from Arduinos. I have also seen projects where people read twitter as a trigger.

What I want to do is this

Tweet sent from phone> Tweet read by Arduino > Arduino feeds pets or makes coffee etc> Arduino replies to me to let me know my bidding is done> I rest safe in the knowledge my trivial tasks are cared for.

Has anyone seen an example of this?
Do you think it is possible?
It seems possible. I'm cautious that no one has done it before to my knowledge.

Regards

Stu
95  Using Arduino / Project Guidance / Re: Ethernet and LCD shield compatibility on: August 31, 2012, 12:56:40 pm
Thank you for your help. That's great news. I'm not using the buttons or SD card for this project.

Unfortunatly I'm in the UK so I won't be buying the spacers from the U.S.
Thanks for the link though, this project does need them.
96  Using Arduino / Project Guidance / Ethernet and LCD shield compatibility on: August 31, 2012, 11:14:55 am
Hello
I'm starting a new project involving an Uno, Arduino Ethernet shield and a Sparkfun LCD-09363.

I would like to be able to stack them all up into a tidy project.

http://shieldlist.org/arduino/ethernet-v5
http://shieldlist.org/sparkfun/colorlcd

I'm not sure if they can function when stacked. I think they both use pins D4, D11 and D13.
Will this cause problems if I try to run them together in this way?

Thanks

Stu
97  Using Arduino / Project Guidance / NEW PROJECT tweetable wifi mist/fog machine - feasibility and advice please on: July 02, 2012, 08:24:11 am
Hello,
I plan to create a mist machine that can be tweeted to activate it.

The unit will not have mains water supply, I will use a unit with a storage tank - http://www.cloudtops.com/misting_systems_misting_nozzles/misting_systems.php

I will not be able to fit an ethernet cable, I plan to use the wiFly shield with an arduino Uno. Tweeting the unit will activate the pump.
http://www.sparkfun.com/products/9954

A couple questions..

Will the wiFly shield work with the twitter library?
What is the best way to get an instant result from the fogger?
Will a transistor work when trying to control the power to the fogger from the arduino?
98  Using Arduino / Programming Questions / Re: 3 days of confusion. Help please on: May 20, 2012, 05:14:47 pm
Thanks, This works a treat.
Inbox me your paypal, I'm getting you a latte!

Code:
unsigned long startTime = 0;
    unsigned long time = millis();
    unsigned long timeout = 10000;
    if(time - startTime > timeout) {
   
Mp3WriteRegister(SPI_AICTRL3, 0x00,0x01);
}
99  Community / Local Groups / Re: South West UK on: May 20, 2012, 12:23:01 pm
I'm in North Devon, Near Bideford.
I'm currently at Uni in Falmouth... I travel down there every couple of weeks to check in.
100  Using Arduino / Programming Questions / Re: 3 days of confusion. Help please on: May 20, 2012, 12:16:35 pm
http://seeedstudio.com/wiki/Music_Shield

I'm working with this as a library ..... http://www.seeedstudio.com/wiki/File:Music_v1_2.zip
101  Using Arduino / Programming Questions / Re: 3 days of confusion. Help please on: May 20, 2012, 11:50:41 am
The record library file I've been working with is here -

Code:
/** \file record.c ADPCM Recording */
#include "record.h"
#include "filesys.h"
#include "storage.h"
#include "vs10xx.h"
#include "hardwareserial.h"
#include "ui.h"
#include "config.h"
#include  <avr/pgmspace.h>

//extern unsigned char SPMax;



#include "venc44k2q05.h"
//#include "oggvorbis_44k2ch.plg"


void LoadUserCode(void)
{
  int i = 0;
  int length = sizeof(plugin);
  int dataSize = sizeof(plugin[0]);

  Serial.print("\r\nLoadUserCode ...");
  while (i<length/dataSize)
  {
    unsigned short addr, n, val;
    addr = pgm_read_word(&plugin[i++]);
    n = pgm_read_word(&plugin[i++]);
    if (n & 0x8000U) { /* RLE run, replicate n samples */
      n &= 0x7FFF;
      val = pgm_read_word(&plugin[i++]);
      while (n--) {
        Mp3WriteRegister(addr, val>>8, val & 0xff);
      }
    }
    else {           /* Copy run, copy n samples */
      while (n--) {
        val = pgm_read_word(&plugin[i++]);
        Mp3WriteRegister(addr, val>>8, val & 0xff);
      }
    }
  }
  Serial.println("over!");
}


const unsigned short linToDBTab[5] = {
  36781, 41285, 46341, 52016, 58386};

/*
  Converts a linear 16-bit value between 0..65535 to decibels.
 Reference level: 32768 = 96dB (largest VS1053 number is 32767 = 95dB).
 Bugs:
 - For the input of 0, 0 dB is returned, because minus infinity cannot
 be represented with integers.
 - Assumes a ratio of 2 is 6 dB, when it actually is approx. 6.02 dB.
 */
unsigned short LinToDB(unsigned short n) {
  int res = 96, i;

  if (!n)               /* No signal should return minus infinity */
    return 0;

  while (n < 32768U) { /* Amplify weak signals */
    res -= 6;
    n <<= 1;
  }

  for (i=0; i<5; i++)   /* Find exact scale */
    if (n > linToDBTab[i])
      res++;

  return res;
}


unsigned char Record()
{
  unsigned char blockNumber;
  unsigned long sectorCount;
  unsigned long lastSector;
  unsigned char stopRecording = 0;
  unsigned char continueRecording = 0;
  char newDisplayValue ;



  blockNumber = 0;
  sectorCount = 1;

  playingState = PS_RECORDING; //Inform the world that rec mode is on.


  // Locate free space
  /** This recording function can only save data into a continuous
   * area on disk. The Fragment Table fragment[] is used in a special way
   * for recording (to save microcontroller RAM space).
   * fragment[0].start is the first disk sector of the file
   * fragment[0].length will contain the number of disk sectors for the file.
   *
   * \bug In case of fragmented filesystem, this version will not
   * function properly.
   */
  // Locate a free sector on storage. Uses global u_int freeSector
  freeSector = 0;
  ScanForFreeSector();
  sectorAddress.l = freeSector;
  fragment[0].start = freeSector;
  lastSector = freeSector;
  dataBufPtr = diskSect.raw.buf;
  blockNumber = 0;
  Serial.print("\r\nRecording, push button to stop...");


  // Kick vs10xx into action!
  Mp3SoftResetWithoutPatch();
  Mp3WriteRegister(SPI_CLOCKF,  0xc0,0x00);
  delay(1);
  while(!MP3_DREQ);
  Mp3WriteRegister(SPI_BASS, 0x00,0x00);
  delay(1);
  while(!MP3_DREQ);
  Mp3WriteRegister(SPI_AIADDR, 0x00,0x00);
  Mp3WriteRegister(SPI_WRAMADDR, 0xC0,0x1A);
  Mp3WriteRegister(SPI_WRAM, 0x00,0x02);
  LoadUserCode();
  Mp3WriteRegister(SPI_MODE, 0x58,0x00);
  delay(1);
  while(!MP3_DREQ);
  Mp3WriteRegister(SPI_AICTRL0, 0x00,0x00);
  delay(1);
  while(!MP3_DREQ);
  Mp3WriteRegister(SPI_AICTRL1, 0x00,0x00);
  delay(1);
  while(!MP3_DREQ);
  Mp3WriteRegister(SPI_AICTRL2, 0x10,0x00);
  delay(1);
  while(!MP3_DREQ);
  Mp3WriteRegister(SPI_AICTRL3, 0x00,0x00);
  delay(1);
  while(!MP3_DREQ);
  Mp3WriteRegister(SPI_AIADDR, 0x00,0x34);
  delay(1);
  while(!MP3_DREQ);


  while(!stopRecording)
  {

    //Delay(100);

    //sample in block[0] and [1]
    signed int soundlevel;
    // the user interface (level bar) calculation

    if (0 == PSKey)
    {   //Request to stop recording
      delay(20);
      while(0 == PSKey);
      delay(20);

      Mp3WriteRegister(SPI_AICTRL3, 0x00,0x01);
    }

    // Ok to stop recording?
    if (Mp3ReadRegister(SPI_AICTRL3) & 1){
      stopRecording = 1;
    }

    soundlevel = Mp3ReadRegister(SPI_AICTRL0);
    Mp3WriteRegister(SPI_AICTRL0,0,0);

    if (soundlevel){
      soundlevel = LinToDB(soundlevel);
      soundlevel *= 3;
      soundlevel -= 185;
      if (soundlevel < 0) soundlevel = 0;
      newDisplayValue = soundlevel;
      //displayValue = newDisplayValue;
    }
    //AvailableProcessorTime();      

    
    
    if (Mp3ReadRegister(SPI_HDAT1) > 255){
      //there is a data block to be read...
      //Serial.println("test here 1");
      GREEN_LED_ON();
      blockNumber++;
      dataBufPtr = diskSect.raw.buf;

      for (temp.c=0;temp.c<128;temp.c++){
        unsigned int i;
        i = Mp3ReadRegister(SPI_HDAT0);
        *dataBufPtr++ = (i>>8);
        *dataBufPtr++ = (i&0xff);
        i = Mp3ReadRegister(SPI_HDAT0);
        *dataBufPtr++ = (i>>8);
        *dataBufPtr++ = (i&0xff);
      }

      //Release SCI chip select, we might want to use MMC card
      Mp3DeselectControl();

      RED_LED_ON();
      blockNumber = 0;
      sectorCount++;
      WriteDiskSector(sectorAddress.l);
      lastSector = freeSector;
      ScanForFreeSector(); //this would be the proper way to go...
      sectorAddress.l = freeSector; //keep all variables in proper values
      dataBufPtr = diskSect.raw.buf; //reset data buffer pointer
      if (freeSector!=(lastSector+1)){ //end of continuous space, must break!
        stopRecording = 1;
        Serial.println("\r\nFragment end - can't continue recording!");
        //InitDisplay(DS_STATIC,"FRAGMENT"," LIMIT!!",0);
        continueRecording = 1;
      }

      RED_LED_OFF();
      GREEN_LED_OFF();

      //if there was data to read
    }
    else
    {
      //Serial.println("test here 2");
      delay(1);
    }

  }//while not button - stop recording when BUTTON is pressed

  while (Mp3ReadRegister(SPI_HDAT1) > 0){
    int n = Mp3ReadRegister(SPI_HDAT1);
    n -= 256;


    //there is a data block to be read...
    GREEN_LED_ON();
    blockNumber++;
    dataBufPtr = diskSect.raw.buf;

    for (temp.c=0;temp.c<128;temp.c++){
      unsigned int i;
      i = Mp3ReadRegister(SPI_HDAT0);
      *dataBufPtr++ = (i>>8);
      *dataBufPtr++ = (i&0xff);
      i = Mp3ReadRegister(SPI_HDAT0);
      *dataBufPtr++ = (i>>8);
      *dataBufPtr++ = (i&0xff);
    }

    if (n<0) {
      for (temp.c = 0; temp.c<(-n); temp.c++){
        *--dataBufPtr = 0;
        *--dataBufPtr = 0;
      }
    }


    //Release SCI chip select, we might want to use MMC card
    Mp3DeselectControl();

    RED_LED_ON();
    blockNumber = 0;
    sectorCount++;
    WriteDiskSector(sectorAddress.l);
    lastSector = freeSector;
    ScanForFreeSector(); //this would be the proper way to go...
    sectorAddress.l = freeSector; //keep all variables in proper values
    dataBufPtr = diskSect.raw.buf; //reset data buffer pointer
    if (freeSector!=(lastSector+1)){ //end of continuous space, must break!
      stopRecording = 1;

      //InitDisplay(DS_STATIC,"FRAGMENT"," LIMIT!!",0);
      continueRecording = 1;
    }

    RED_LED_OFF();
    GREEN_LED_OFF();

    if (n<0){
      break;
    }

  }


  fragment[0].length = sectorCount;    
  //Create FAT records.
  fragment[1].start = 0x0fffffff; //fragment 0 is the only fragment
  WriteClusterChain(); //register newly created file in FAT FS

  // \todo second FAT table update

  sectorAddress.l = 0; //force sector reload for next access

  Mp3SoftReset();
  return PS_NEXT_SONG;

}

102  Using Arduino / Programming Questions / 3 days of confusion. Help please on: May 20, 2012, 11:50:28 am
I'm setting the music shield to Record(); when an accelerometer is tilted and Play(); when it is level.

At the moment it needs a reboot to switch between the two modes. This is fine as it fits the design of the project. There will be a microswitch cutting power to the arduino.

 What I need to do is make sure after 10 seconds in record mode it saves the file and enters the play mode. The record function is normally ended by the PSKey button on the music shield. I just need it done digitally after a delay(10000);
I can't figure out how to get this done. This is my first arduino project and It's starting to make my head hurt.

If you could find it in your heart to help a simple Devonian fool work out this problem I'll buy you a latte or something.
Cheers.

My code is here -

Code:
#include <avr/io.h>
#include "config.h"
#include "filesys.h"
#include "player.h"
#include "vs10xx.h"
#include "record.h"
#include <SoftwareSerial.h>


const int groundpin = 66;             // analog input pin 4 -- ground
const int powerpin = 67;              // analog input pin 5 -- voltage
const int xpin = A11;                  // x-axis of the accelerometer
const int ypin = A10;                  // y-axis od the accelerometer

SoftwareSerial mySerial(2, 3);

void setup()
{
  Serial.begin(9600);
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW);
  digitalWrite(powerpin, HIGH);
  
  InitSPI();
  InitIOForVs10xx();
  InitIOForKeys();
  InitIOForLEDs();
  InitFileSystem();
  Mp3Reset();
}


void loop()
{
 if(analogRead(xpin) > 589 ||analogRead(xpin) < 433||analogRead(ypin) > 589 ||analogRead(ypin) < 433)
{
  Record();

/********** I need something in here to stop the recording. Else it does not save the recording if the device resets before it has time to close the file***************/
  
}

 if(analogRead(xpin) < 589 ||analogRead(xpin) > 433||analogRead(ypin) < 589 ||analogRead(ypin) > 433)
{
 Play();
}

}




103  Using Arduino / Project Guidance / Re: New to Arduino - Looking for advice on: May 16, 2012, 12:55:44 pm
since it's such a small application you might want to build a prototype with an arduino uno and then learn to program your own microcontroller with PICAXE. This will save you a lot of battery life in the long run.

Also, take a look at Fritzing. I think you'll find it a useful tool to get to grips with how everything works/schematics and the like.
104  Using Arduino / Project Guidance / Re: New to Arduino - Looking for advice on: May 16, 2012, 12:18:46 pm
It's a great place to start if you are new, although for your prototype it could be considered a little big. If you're going to use it again for other prototypes get the uno or MEGA. If not then shop for something smaller.
Proto-pic is a good UK site, I don't know where you live though.

One issue with this for me.. It will have to be turned on all the time which will use a lot of battery power. Do you know how you are planning on powering it?

105  Using Arduino / Project Guidance / Re: New to Arduino - Looking for advice on: May 16, 2012, 11:43:09 am
It will be possible and quite easy to make the initial test.
You could use a piezo to test vibrations. This one works okay but shop around because there are loads out there.
This could turn the LED on upon impact.
http://www.sparkfun.com/products/9199
Pages: 1 ... 5 6 [7] 8 9