Newsoftserial and servo motor

Hi,

I have an MLX90614 from parallax and a servo motor. I want to make the servo motor spin around while MLX90614 keep picking up temperature. The servo shall stop when MLX90614 pick up high temperature (fire for ex).

I'm able to read temperature from sensor thanks to:

and I'm able to spin servo motor thanks to Arduino example.

But when I put both together. myservo.attach() return 0 (according to servo library it's a bad thing) and program stop at rChar = Temp10.read();

I'm susspecting newsoftserial library interfere somehow. Has anyone seen this problem before?

Thanks a millions

#include <Servo.h>
#include <SoftwareSerial.h>

Servo myservo;
SoftwareSerial Temp10(2, 3);

int pos = 0;    // variable to store the servo position 
int prev_temp =0;
int LED=13;   /* for the show  */
int RESET=12;

void setup()
{
 pinMode(2,OUTPUT);
 pinMode(3,OUTPUT);
 pos = myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
 Serial.print(pos,DEC);

 Temp10.begin(4800);
 Serial.begin(115200);

 delay(100);
 Temp10.print(0,BYTE);
 Temp10.print("!TEMc");
 Temp10.print(0x5A,BYTE);
 Temp10.print(7,BYTE);

 pinMode(2,INPUT);
 pinMode(3,INPUT);
 delay(10);
}

void loop()
{

  for (pos = 0; pos <= 2000; pos +=10)
  {
    prev_temp = Acqu_Temp();
    Serial.print("Temperature= ");
    Serial.print(prev_temp,DEC);
    Serial.println(" Degrees Celsius");
  }
  
   delay(500);  
}

//----------------------------------

int Acqu_Temp()
{
 static char rByte[10];
 char rChar;
 int Temp1, Temp2, Temp3;

   rChar = Temp10.read();
   if (rChar == 'T') {
     rByte[0]=rChar;
     rChar=Temp10.read();
     if(rChar=='E')
     {
         rByte[1]=rChar;
         rChar=Temp10.read();
         if(rChar=='M')
         {
           rByte[2]=rChar;
           rByte[3]=Temp10.read();
           rByte[4]=Temp10.read();
           rByte[5]=Temp10.read();
           Temp1 = rByte[4] + rByte[5]*256;           
           Temp3 = (Temp1/100*2)-273;
         }
     }
   }

 return(Temp3);
}

NewSoftSerial does not work with the Servo library because it blocks interrupts and this interferes with the Servo timing.

If you only need to drive one or two servos, you could use the servo library from arduino release 0016, this only drives two servos and these must be connected to pins 9 and 10, but it does not use interrupts so will work with NewSoftSerial

Hi mem,

Thank you very much for the hint, i'm downloading arduino 016 right now.

I need to control 3 motors in my projects (all servos) is there anyway i can do this?

Thanks again

Can you use Hardware serial for connection to the MLX chip?

What are you making?

the MLX has only 1 serial pin (both tx and rx in 1 pin)

I found intruction on using newsoftserial to communicate through general I/O pins, and it work fines, I have more than 1 sensors too so there wont be enough hardware serial for sure.

I'm making a high temperature detector, with mlx90614 spining around picking up heat signature, and motors to stop when it does

There are a number of ways to solve this. One of the easiest is to use another board to drive the servos. For example: http://www.moderndevice.com/products/rbbb-kit
This would drive up to 12 servos and its hardware serial port can be connected to a digital pin on your main arduino board that is driving the sensors.

Another way using just your existing board is to drive the servos without interrupts. By controlling the servo pulse widths explicitly in software you can do your serial communications in the 16 milliseconds or so servo refresh period.

A third possibility if you have not already purchased the three parallax boards could save yourself a lot of money by driving using the raw chip directly using the wire library. The raw chips are half the price or less of the Parallax boards : Infrared Thermometer - MLX90614 - SEN-09570 - SparkFun Electronics)

The datasheet for the MLX90614 indicates it uses a signalling protocol similar to I2C (the protocol used by the Arduino Wire library) so you may be able to connect them up directly without NewSoftSerial. If you like this option, do some research to see if anyone has got this working.