Show Posts
|
|
Pages: [1] 2 3 ... 6
|
|
1
|
Using Arduino / Project Guidance / control analog signal using xbee and arduino uno
|
on: May 13, 2013, 08:33:14 am
|
i need to read any analog sensor like variable resistance and show it in another board on lcd i try to control digital signal and i success in this code Receiver _______ int LEDredPin =12; int LEDgreenPin = 13; void setup() {
Serial.begin(9600); pinMode(LEDredPin, OUTPUT); pinMode(LEDgreenPin, OUTPUT);
}
void loop() { if (Serial.available()) { //If there is data in the Serial Line int dataByte = Serial.read();
if(dataByte == 'H'){ digitalWrite(LEDredPin, HIGH); digitalWrite(LEDgreenPin, LOW);
}
if(dataByte == 'L') { digitalWrite(LEDgreenPin, HIGH); digitalWrite(LEDredPin, LOW); } } } Transmitter ___________ const int sw1=2; const int sw2=3; void setup() { pinMode(2,INPUT); pinMode(3,INPUT); Serial.begin(9600); }
void loop() { if(digitalRead(sw1)==1) { Serial.print('H'); } if(digitalRead(sw2)==1) { Serial.print('L'); } } but when i try to make analog signal i failed like this code transmitter __________ void setup() { Serial.begin(9600); }
void loop() { Serial.println(analogRead(A0)); } Receiver ________ #include <LiquidCrystal.h> LiquidCrystal lcd(7,8,9,10,11,12); void setup() { Serial.begin(9600); lcd.begin(16, 2); }
void loop() { if (Serial.available()) { //If there is data in the Serial Line int dataByte = Serial.read(); lcd.setCursor(0, 1); lcd.print(dataByte);
} }
|
|
|
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / control analog signal using xbee and arduino uno
|
on: May 13, 2013, 08:32:46 am
|
i need to read any analog sensor like variable resistance and show it in another board on lcd i try to control digital signal and i success in this code Receiver _______ int LEDredPin =12; int LEDgreenPin = 13; void setup() {
Serial.begin(9600); pinMode(LEDredPin, OUTPUT); pinMode(LEDgreenPin, OUTPUT);
}
void loop() { if (Serial.available()) { //If there is data in the Serial Line int dataByte = Serial.read();
if(dataByte == 'H'){ digitalWrite(LEDredPin, HIGH); digitalWrite(LEDgreenPin, LOW);
}
if(dataByte == 'L') { digitalWrite(LEDgreenPin, HIGH); digitalWrite(LEDredPin, LOW); } } } Transmitter ___________ const int sw1=2; const int sw2=3; void setup() { pinMode(2,INPUT); pinMode(3,INPUT); Serial.begin(9600); }
void loop() { if(digitalRead(sw1)==1) { Serial.print('H'); } if(digitalRead(sw2)==1) { Serial.print('L'); } } but when i try to make analog signal i failed like this code transmitter __________ void setup() { Serial.begin(9600); }
void loop() { Serial.println(analogRead(A0)); } Receiver ________ #include <LiquidCrystal.h> LiquidCrystal lcd(7,8,9,10,11,12); void setup() { Serial.begin(9600); lcd.begin(16, 2); }
void loop() { if (Serial.available()) { //If there is data in the Serial Line int dataByte = Serial.read(); lcd.setCursor(0, 1); lcd.print(dataByte);
} }
|
|
|
|
|
3
|
Using Arduino / Project Guidance / Re: ECG-EMG Arduino Shield
|
on: May 12, 2013, 05:45:28 am
|
It looks as if the data is stored in TXBuf.
It also looks as if it's doing serial output within an interrupt service routine, which is not generally regarded as a smart thing to do, but if it's not causing a problem then I suppose you could ignore that.
i try to read data from TXBuf but i failed can you tell me how can i read it ? thanks
|
|
|
|
|
4
|
Using Arduino / Project Guidance / ECG-EMG Arduino Shield
|
on: May 11, 2013, 05:20:53 pm
|
i need to know where the data of sensor saved because i need signal from sensor andmove servo motors i use this sheild http://store.fut-electronics.com/111MED0002.htmlhttp://store.fut-electronics.com/111MED0003.html/**********************************************************/ /* Demo program for: */ /* Board: SHIELD-EKG/EMG + Olimexino328 */ /* Manufacture: OLIMEX */ /* COPYRIGHT (C) 2012 */ /* Designed by: Penko Todorov Bozhkov */ /* Module Name: Sketch */ /* File Name: ShieldEkgEmgDemo.ino */ /* Revision: Rev.A */ /* -> Added is suppport for all Arduino boards. */ /* This code could be recompiled for all of them! */ /* Date: 19.12.2012 */ /* Built with Arduino C/C++ Compiler, version: 1.0.3 */ /**********************************************************/ /********************************************************** Purpose of this programme is to give you an easy way to connect Olimexino328 to ElectricGuru(TM), see: https://www.olimex.com/Products/EEG/OpenEEG/EEG-SMT/resources/ElecGuru40.zip where you'll be able to observe yours own EKG or EMG signal. It is based on: *********************************************************** * ModularEEG firmware for one-way transmission, v0.5.4-p2 * Copyright (c) 2002-2003, Joerg Hansmann, Jim Peters, Andreas Robinson * License: GNU General Public License (GPL) v2 *********************************************************** For proper communication packet format given below have to be supported: /////////////////////////////////////////////// ////////// Packet Format Version 2 //////////// /////////////////////////////////////////////// // 17-byte packets are transmitted from Olimexino328 at 256Hz, // using 1 start bit, 8 data bits, 1 stop bit, no parity, 57600 bits per second.
// Minimial transmission speed is 256Hz * sizeof(Olimexino328_packet) * 10 = 43520 bps.
struct Olimexino328_packet { uint8_t sync0; // = 0xa5 uint8_t sync1; // = 0x5a uint8_t version; // = 2 (packet version) uint8_t count; // packet counter. Increases by 1 each packet. uint16_t data[6]; // 10-bit sample (= 0 - 1023) in big endian (Motorola) format. uint8_t switches; // State of PD5 to PD2, in bits 3 to 0. }; */ /**********************************************************/ #include <compat/deprecated.h> #include <FlexiTimer2.h> //http://www.arduino.cc/playground/Main/FlexiTimer2
// All definitions #define NUMCHANNELS 6 #define HEADERLEN 4 #define PACKETLEN (NUMCHANNELS * 2 + HEADERLEN + 1) #define SAMPFREQ 256 // ADC sampling rate 256 #define TIMER2VAL (1024/(SAMPFREQ)) // Set 256Hz sampling frequency #define LED1 13 #define CAL_SIG 9
// Global constants and variables volatile unsigned char TXBuf[PACKETLEN]; //The transmission packet volatile unsigned char TXIndex; //Next byte to write in the transmission packet. volatile unsigned char CurrentCh; //Current channel being sampled. volatile unsigned char counter = 0; //Additional divider used to generate CAL_SIG volatile unsigned int ADC_Value = 0; //ADC current value
//~~~~~~~~~~ // Functions //~~~~~~~~~~
/****************************************************/ /* Function name: Toggle_LED1 */ /* Parameters */ /* Input : No */ /* Output : No */ /* Action: Switches-over LED1. */ /****************************************************/ void Toggle_LED1(void){
if((digitalRead(LED1))==HIGH){ digitalWrite(LED1,LOW); } else{ digitalWrite(LED1,HIGH); } }
/****************************************************/ /* Function name: toggle_GAL_SIG */ /* Parameters */ /* Input : No */ /* Output : No */ /* Action: Switches-over GAL_SIG. */ /****************************************************/ void toggle_GAL_SIG(void){ if(digitalRead(CAL_SIG) == HIGH){ digitalWrite(CAL_SIG, LOW); } else{ digitalWrite(CAL_SIG, HIGH); } }
/****************************************************/ /* Function name: setup */ /* Parameters */ /* Input : No */ /* Output : No */ /* Action: Initializes all peripherals */ /****************************************************/ void setup() {
noInterrupts(); // Disable all interrupts before initialization // LED1 pinMode(LED1, OUTPUT); //Setup LED1 direction digitalWrite(LED1,LOW); //Setup LED1 state pinMode(CAL_SIG, OUTPUT); //Write packet header and footer TXBuf[0] = 0xa5; //Sync 0 TXBuf[1] = 0x5a; //Sync 1 TXBuf[2] = 2; //Protocol version TXBuf[3] = 0; //Packet counter TXBuf[4] = 0x02; //CH1 High Byte TXBuf[5] = 0x00; //CH1 Low Byte TXBuf[6] = 0x02; //CH2 High Byte TXBuf[7] = 0x00; //CH2 Low Byte TXBuf[8] = 0x02; //CH3 High Byte TXBuf[9] = 0x00; //CH3 Low Byte TXBuf[10] = 0x02; //CH4 High Byte TXBuf[11] = 0x00; //CH4 Low Byte TXBuf[12] = 0x02; //CH5 High Byte TXBuf[13] = 0x00; //CH5 Low Byte TXBuf[14] = 0x02; //CH6 High Byte TXBuf[15] = 0x00; //CH6 Low Byte TXBuf[2 * NUMCHANNELS + HEADERLEN] = 0x01; // Switches state
// Timer2 // Timer2 is used to setup the analag channels sampling frequency and packet update. // Whenever interrupt occures, the current read packet is sent to the PC // In addition the CAL_SIG is generated as well, so Timer1 is not required in this case! FlexiTimer2::set(TIMER2VAL, Timer2_Overflow_ISR); FlexiTimer2::start(); // Serial Port Serial.begin(57600); //Set speed to 57600 bps // MCU sleep mode = idle. //outb(MCUCR,(inp(MCUCR) | (1<<SE)) & (~(1<<SM0) | ~(1<<SM1) | ~(1<<SM2))); interrupts(); // Enable all interrupts after initialization has been completed }
/****************************************************/ /* Function name: Timer2_Overflow_ISR */ /* Parameters */ /* Input : No */ /* Output : No */ /* Action: Determines ADC sampling frequency. */ /****************************************************/ void Timer2_Overflow_ISR() { // Toggle LED1 with ADC sampling frequency /2 Toggle_LED1(); //Read the 6 ADC inputs and store current values in Packet for(CurrentCh=0;CurrentCh<6;CurrentCh++){ ADC_Value = analogRead(CurrentCh); TXBuf[((2*CurrentCh) + HEADERLEN)] = ((unsigned char)((ADC_Value & 0xFF00) >> 8)); // Write High Byte TXBuf[((2*CurrentCh) + HEADERLEN + 1)] = ((unsigned char)(ADC_Value & 0x00FF)); // Write Low Byte } // Send Packet for(TXIndex=0;TXIndex<17;TXIndex++){ Serial.write(TXBuf[TXIndex]); } // Increment the packet counter TXBuf[3]++; // Generate the CAL_SIGnal counter++; // increment the devider counter if(counter == 12){ // 250/12/2 = 10.4Hz ->Toggle frequency counter = 0; toggle_GAL_SIG(); // Generate CAL signal with frequ ~10Hz } }
/****************************************************/ /* Function name: loop */ /* Parameters */ /* Input : No */ /* Output : No */ /* Action: Puts MCU into sleep mode. */ /****************************************************/ void loop() { __asm__ __volatile__ ("sleep"); }
|
|
|
|
|
6
|
Products / Arduino GSM Shield / Re: GSM receive message and make action
|
on: May 11, 2013, 06:36:05 am
|
Hi:
You are receiving ascii characters. So, if you are sending a SMS with the text: 1
or with the text
0
you have to compare it like this: if(c== '1') {digitalWrite(led,HIGH); } if(c== '0') {digitalWrite(led,LOW); }
Good luck, and please tell us how are you doing.
this code is work good but i need to send 'on' or 'off' to make action
|
|
|
|
|
11
|
Using Arduino / Project Guidance / Serial.read more than letter
|
on: May 06, 2013, 12:08:31 pm
|
i try to make led high when enter 'on' in serial monitor and low when write 'off' i need to know why this code not operate int ledPin=13; char a[2] = {'o', 'n'}; char b[3] = {'o', 'f', 'f'}; char c[3] ;
void setup () { Serial.begin(9600); pinMode(ledPin,OUTPUT);
} void loop () { c[3] = Serial.read(); { if ((a[0]==c[0])&&(a[1]==c[1])) {digitalWrite(ledPin,HIGH); } if (b[0] == c[0]&&b[1] == c[1]&&b[2] == c[2]) {digitalWrite(ledPin,LOW); } } }
|
|
|
|
|
12
|
Products / Arduino GSM Shield / GSM receive message and make action
|
on: May 06, 2013, 08:44:09 am
|
please i need when sent message like on make led HIGH and when sent low make led LOW #include <GSM.h>
// PIN Number for the SIM #define PINNUMBER ""
// initialize the library instances GSM gsmAccess; GSM_SMS sms;
// Array to hold the number a SMS is retreived from char senderNumber[20]; const int led = 13; void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }
Serial.println("SMS Messages Receiver"); // connection state boolean notConnected = true; // Start GSM connection while(notConnected) { if(gsmAccess.begin(PINNUMBER)==GSM_READY) notConnected = false; else { Serial.println("Not connected"); delay(1000); } } Serial.println("GSM initialized"); Serial.println("Waiting for messages"); pinMode(led,OUTPUT); digitalWrite(led,LOW); }
void loop() { char c; // If there are any SMSs available() if (sms.available()) { Serial.println("Message received from:"); // Get remote number sms.remoteNumber(senderNumber, 20); Serial.println(senderNumber);
// An example of message disposal // Any messages starting with # should be discarded if(sms.peek()=='#') { Serial.println("Discarded SMS"); sms.flush(); } // Read message bytes and print them while(c=sms.read()) Serial.print(c); if(c== 1) {digitalWrite(led,HIGH); } if(c== 0) {digitalWrite(led,LOW); } Serial.println("\nEND OF MESSAGE"); // Delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); }
delay(1000);
} i receive message without make action for led ineed to know how check condition when receive message // Read message bytes and print them while(c=sms.read()) Serial.print(c); if(c== 1) {digitalWrite(led,HIGH); } if(c== 0) {digitalWrite(led,LOW); } Serial.println("\nEND OF MESSAGE"); // Delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); } how check c if message sent 1 for HIGH and 0 for LOW i use this shield http://arduino.cc/en/Main/ArduinoGSMShieldthanks 
|
|
|
|
|
14
|
Using Arduino / Project Guidance / GSM receive message and make action
|
on: May 04, 2013, 12:16:35 pm
|
please i need when sent message like on make led HIGH and when sent low make led LOW /* SMS receiver This sketch, for the Arduino GSM shield, waits for a SMS message and displays it through the Serial port. Circuit: * GSM shield attached to and Arduino * SIM card that can receive SMS messages created 25 Feb 2012 by Javier Zorzano / TD This example is in the public domain. http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS */
// include the GSM library #include <GSM.h>
// PIN Number for the SIM #define PINNUMBER ""
// initialize the library instances GSM gsmAccess; GSM_SMS sms;
// Array to hold the number a SMS is retreived from char senderNumber[20]; const int led = 13; void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }
Serial.println("SMS Messages Receiver"); // connection state boolean notConnected = true; // Start GSM connection while(notConnected) { if(gsmAccess.begin(PINNUMBER)==GSM_READY) notConnected = false; else { Serial.println("Not connected"); delay(1000); } } Serial.println("GSM initialized"); Serial.println("Waiting for messages"); pinMode(led,OUTPUT); digitalWrite(led,LOW); }
void loop() { char c; // If there are any SMSs available() if (sms.available()) { Serial.println("Message received from:"); // Get remote number sms.remoteNumber(senderNumber, 20); Serial.println(senderNumber);
// An example of message disposal // Any messages starting with # should be discarded if(sms.peek()=='#') { Serial.println("Discarded SMS"); sms.flush(); } // Read message bytes and print them while(c=sms.read()) Serial.print(c); if(c== 1) {digitalWrite(led,HIGH); } if(c== 0) {digitalWrite(led,LOW); } Serial.println("\nEND OF MESSAGE"); // Delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); }
delay(1000);
}
i receive message without make action for led ineed to know how check condition when receive message // Read message bytes and print them while(c=sms.read()) Serial.print(c); if(c== 1) {digitalWrite(led,HIGH); } if(c== 0) {digitalWrite(led,LOW); } Serial.println("\nEND OF MESSAGE"); // Delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); } how check c if message sent 1 for HIGH and 0 for LOW
|
|
|
|
|