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... for (int i = 0; i < 4; i++){ if (twitter.post(buttonPressed[i])) full 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{ } }
|
|
|
|
|
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
|
|
|
|
|
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! 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.
|
|
|
|
|
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 - /** \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 - #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?
|
|
|
|
|