Hi guys,
In my current project I built a box in which I control temperature and humidity. In the box I would like to do some motor actuation. However, I ran into a few problems.
For measuring temperature and humidity I'm using the SHT11 sensor. Using simple ON/OFF control I'm able to control the climate. For driving the stepper motor I'm using the big easy driver board. Individually, both work fine.
Now, when combining both systems I ran into some trouble. Polling the sensor does take a fair amount of time, which does not allow for climate control during actuation, as I require a smooth movement.
My code is as follows:
//Libraries
#include <AccelStepper.h>
#include <stdlib.h>
#include <Timer.h>
#include <SHT1x.h>
//Pins
#define pinMotorStep 0 // define pin for stepping
#define pinMotorDirection 1 // define pin for the motor direction
#define pinMotorOnOff 2 // switch for starting the friction measurements
#define pinSensorClock 5 // current relative humidity and temperature measured by the sensor
#define pinSensorData 6 // pin used for clock sensor
#define pinRelayHumidifier 7 // switch for putting on/off the ultrasonic humidifier
//Create instances
AccelStepper stepperMotor(1,pinMotorStep,pinMotorDirection); // 1: Dedicated driver board
Timer T;
SHT1x sht1x(pinSensorData, pinSensorClock);
//Climate Settings
int setRelativeHumidity = 60;
//Drive setting
double stepsPerRevolution = 3200;
double pitchSpindle = 4;
double slidingSpeed = 0.2;
double slidingLength = 32;
double pauseTime = 0;
double slidingDirection = 1;
//Run once
void setup(){
pinMode(pinRelayHumidifier, OUTPUT);
pinMode(pinSensorClock , INPUT);
pinMode(pinSensorData , INPUT);
stepperMotor.setMaxSpeed((slidingSpeed/pitchSpindle)*stepsPerRevolution);
stepperMotor.setAcceleration((slidingSpeed/pitchSpindle)*stepsPerRevolution);
digitalWrite(pinRelayHumidifier, LOW);
T.every(2000,humidifierOnOff);
Serial.begin(9600);
}
//Main program
void loop(){
if (digitalRead(pinMotorOnOff)==LOW)
{
T.update();
}
if (digitalRead(pinMotorOnOff)==HIGH)
{
if (stepperMotor.distanceToGo()==0)
{
stepperMotor.moveTo(slidingDirection*(slidingLength/pitchSpindle)*stepsPerRevolution/2);
slidingDirection = -slidingDirection;
}
stepperMotor.run();
}
}
//Subfunctions
void humidifierOnOff(){
//Get current state
float currentTemperature = sht1x.readTemperatureC();
float currentRelativeHumidity = sht1x.readHumidity();
Serial.print(currentTemperature);
Serial.print('\t');
Serial.print(currentRelativeHumidity);
Serial.print('\n');
//Compare with set value
if (setRelativeHumidity-currentRelativeHumidity>2.0)
{
digitalWrite(pinRelayHumidifier, HIGH);
}
else
{
digitalWrite(pinRelayHumidifier, LOW);
}
}
Do you have any suggestions how I can combine both systems, such that I still have a smooth movement and climate control during this actuation?
I tryed to move the actuation part to an AtTiny2313 but this gave errors during compiling:
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn2313.o:(.init9+0x0): relocation truncated to fit: R_AVR_13_PCREL against symbol `main' defined in .text.main section in core.a(main.cpp.o)
c:/program files
...
... Arduino\libraries\AccelStepper/AccelStepper.cpp:406: additional relocation overflows omitted from the output
What does this error mean? When I remove the AccelStepper instance I don't get compiling errors.
I've googled whether it is possible to use the Attiny in combination with the AccelStepper library, but I couldn't find anything about this subject.
Best regards