Go Down

Topic: FSR sensor to stop servo  (Read 1 time) previous topic - next topic

alialhassany93

Feb 06, 2018, 04:11 pm Last Edit: Feb 10, 2018, 08:21 pm by Coding Badly
hello
 im using neurosky mindwave to control with servo by attention and meditation  to run servo 
and i have FSR sensor to stop these servo
can any one help me this is my code below and need to insert the FSR  to stop servo on any thing touch it   please write to me the code  :
Code: [Select]

#include <Servo.h>
#define BAUDRATE 57600
#define DEBUGOUTPUT 0
#define powercontrol 10
// servo motors
Servo index;
Servo thumb;
// checksum variables
byte generatedChecksum = 0;
byte checksum = 0;
int payloadLength = 0;
byte payloadData[64] = {30};
byte poorQuality = 0;
byte attention = 0;
byte meditation = 0;
// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;
//////////////////////////
// Microprocessor Setup //
//////////////////////////
void setup() {
Serial.begin(BAUDRATE); // USB
index.attach(13);
palm.attach(9);
}
////////////////////////////////
// Read data from Serial UART //
////////////////////////////////
byte ReadOneByte() {
int ByteRead;
while(!Serial.available());
ByteRead = Serial.read();
#if DEBUGOUTPUT
Serial.print((char)ByteRead); // echo the same byte out the USB serial (for debug
purposes)
#endif
return ByteRead;
}
/////////////
//MAIN LOOP//
/////////////
void loop() {
// Look for sync bytes
if(ReadOneByte() == 170) {
if(ReadOneByte() == 170) {
  payloadLength = ReadOneByte();
if(payloadLength > 169) //Payload length can not be greater than 169

return;
generatedChecksum = 0;
for(int i = 0; i < payloadLength; i++) {
payloadData[i] = ReadOneByte(); //Read payload into memory
generatedChecksum += payloadData[i];
}
checksum = ReadOneByte(); //Read checksum byte from stream
generatedChecksum = 255 - generatedChecksum; //Take one's compliment of generated checksum

if(checksum == generatedChecksum) {
poorQuality = 200;
attention = 0;
meditation = 0;
for(int i = 0; i < payloadLength; i++) { // Parse the payload
switch (payloadData[i]) {
case 2:
i++;
poorQuality = payloadData[i];
bigPacket = true;
break;
case 4:
i++;
attention = payloadData[i];
break;
case 5:
i++;
meditation = payloadData[i];
break;
case 0x80:
i = i + 3;
break;
case 0x83:
i = i + 25;
break;
default:
break;
} // switch
} // for loop
#if !DEBUGOUTPUT
if(bigPacket) {
if (attention >= 60) {
Serial.print("Over 80; ");
index.write(10);
}
else {
Serial.print("Under 80; ");
index.write(170);
}
if  (meditation >=80)
  {
 palm.write(10);}
 else{
  palm.write(175);

 }
Serial.print("PoorQuality: ");
Serial.print(poorQuality, DEC);
Serial.print("  Attention: ");
Serial.print(attention, DEC);
Serial.print (" Meditation:");
 Serial.print (meditation,DEC);
Serial.print(" Time since last packet: ");
Serial.print(millis() - lastReceivedPacket, DEC);
lastReceivedPacket = millis();
Serial.print("\n");
}
#endif
bigPacket = false;
}
else {
  // Checksum Error
} // end if else for checksum
} // end if read 0xAA byte
} // end if read 0xAA byte
}


Moderator edit: [code] [/code] tags added.

groundFungus

#1
Feb 06, 2018, 04:48 pm Last Edit: Feb 06, 2018, 04:49 pm by groundFungus
We do not write code for people here.  If you want code written for you, have a moderator move this post to the Gigs and Collaborations section.  Expect to pay.  If you make an attempt at writing the code an post it properly along with an description of what it does and how that differs form what you want the code to do, we can help you to get it working.

Please read the "how to use this forum-please read" stickies to see how to format and post code.  Properly posted code will not be turned into italics and will be properly indented.   Poorly indented code is very hard to read.

alialhassany93

#2
Feb 06, 2018, 05:25 pm Last Edit: Feb 10, 2018, 08:20 pm by Coding Badly
hello
 im using neurosky mindwave to control with servo by attention and meditation  to run servo 
and i have FSR sensor to stop these servo
can any one help me this is my code below and need to insert the FSR  to stop servo on any thing touch it   please write to me the code  :
Code: [Select]

#include <Servo.h>
#define BAUDRATE 57600
#define DEBUGOUTPUT 0
#define powercontrol 10
// servo motors
Servo index;
Servo middle;
Servo ring;
Servo little;
Servo palm;
Servo thumb;
// checksum variables
byte generatedChecksum = 0;
byte checksum = 0;
int payloadLength = 0;
byte payloadData[64] = {30};
byte poorQuality = 0;
byte attention = 0;
byte meditation = 0;
// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;
//////////////////////////
// Microprocessor Setup //
//////////////////////////
void setup() {
Serial.begin(BAUDRATE); // USB
index.attach(13);
palm.attach(9);
}
////////////////////////////////
// Read data from Serial UART //
////////////////////////////////
byte ReadOneByte() {
int ByteRead;
while(!Serial.available());
ByteRead = Serial.read();
#if DEBUGOUTPUT
Serial.print((char)ByteRead); // echo the same byte out the USB serial (for debug
purposes)
#endif
return ByteRead;
}
/////////////
//MAIN LOOP//
/////////////
void loop() {
// Look for sync bytes
if(ReadOneByte() == 170) {
if(ReadOneByte() == 170) {
  payloadLength = ReadOneByte();
if(payloadLength > 169) //Payload length can not be greater than 169

return;
generatedChecksum = 0;
for(int i = 0; i < payloadLength; i++) {
payloadData[i] = ReadOneByte(); //Read payload into memory
generatedChecksum += payloadData[i];
}
checksum = ReadOneByte(); //Read checksum byte from stream
generatedChecksum = 255 - generatedChecksum; //Take one's compliment of generated checksum

if(checksum == generatedChecksum) {
poorQuality = 200;
attention = 0;
meditation = 0;
for(int i = 0; i < payloadLength; i++) { // Parse the payload
switch (payloadData[i]) {
case 2:
i++;
poorQuality = payloadData[i];
bigPacket = true;
break;
case 4:
i++;
attention = payloadData[i];
break;
case 5:
i++;
meditation = payloadData[i];
break;
case 0x80:
i = i + 3;
break;
case 0x83:
i = i + 25;
break;
default:
break;
} // switch
} // for loop
#if !DEBUGOUTPUT
if(bigPacket) {
if (attention >= 60) {
Serial.print("Over 80; ");
index.write(10);
}
else {
Serial.print("Under 80; ");
index.write(170);
}
if  (meditation >=80)
  {
 palm.write(10);}
 else{
  palm.write(175);

 }
Serial.print("PoorQuality: ");
Serial.print(poorQuality, DEC);
Serial.print("  Attention: ");
Serial.print(attention, DEC);
Serial.print (" Meditation:");
 Serial.print (meditation,DEC);
Serial.print(" Time since last packet: ");
Serial.print(millis() - lastReceivedPacket, DEC);
lastReceivedPacket = millis();
Serial.print("\n");
}
#endif
bigPacket = false;
}
else {
  // Checksum Error
} // end if else for checksum
} // end if read 0xAA byte
} // end if read 0xAA byte
}


Moderator edit: [code] [/code] tags added.

wvmarle

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

PaulS

Quote
im using neurosky mindwave to control with servo by attention and meditation  to run servo
Which servo? index? middle? rung? little? palm? thumb?

What pin is the FSR connected to? Where do you read that pin?

You realize, I hope, that since you only tell any given servo to go to some new position IN ONE STEP, that you won't be able to stop the servo until it completes that step.
The art of getting good answers lies in asking good questions.

Coding Badly


@alialhassany93, stop cross-posting.  Threads merged.


alialhassany93

hi
ihave a neurosky mindwave .and ineed a code for arduino consist both eye blink and attention to control servo motors . please any one help me

Coding Badly


@alialhassany93, stop cross-posting.


alialhassany93

hi
can any one help i need acode for arduino control the servo motors with neurosky mind wave and ihave only the code for single eye blink . can any one help me and talk to me change in code and make the code for single and double eye blink

alialhassany93

hi
ineed acode for arduino consist eye blink +attention +medetion for neurosky  togother

jimlee2


robtillaart

Moderator: merged all your 5 threads, do not cross post again.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up