I am currently working on a project where I collect a signal through the ADS1115 when a button is pressed. That part of my sketch is currently working. However I cannot figure out any way to use the setup I have to control the temperature of an "oven" at the same time.
I need to collect data and begin a temperature program when the button is pressed.
An example of a temp program would be:
1: starting temp 40C
2: ramp by xC per min for y min
The poor man's DAC I put in seems to work well when used on it's own, but not with the data collection sketch. Any suggestions on how I should proceed?
Attached is a rough schematic of my DAC
Sketch below
#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;
int nextTime1 = 50;
int nextTime2 = 60000;
unsigned long goTime1, goTime2; // NEEDS TO BE UNSIGNED LONG
int16_t rawADCvalue;
float scalefactor = 0.1875F;
float volts = 0.0;
unsigned long time;
boolean valOne, valTwo = 0;
int triggerPin = 8;
int Pwm = 9;
int Pwm_Value = 20;
bool myVar = false;
//******************************************************************************
void setup()
{
pinMode(triggerPin, INPUT);
pinMode(Pwm, OUTPUT); // set pin to output
Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
Serial.begin(115200); // Baud rate, either 115200 or 9600 works
ads.begin();
} //END of setup()
//******************************************************************************
void loop()
{
if (millis() - goTime1 >= nextTime1)
{
goTime1 = millis();
functionGo1();
}
//*******************************
if (myVar == true)
{
if (millis() - time < 10000UL)
{
rawADCvalue = ads.readADC_Differential_0_1();
volts = (rawADCvalue * scalefactor) / 1000.0;
Serial.print("Raw ADC Value = ");
Serial.print(rawADCvalue);
Serial.print("\tVoltage Measured = ");
Serial.println(volts, 6);
Serial.println();
}
else
{
myVar = false; //we are now finished with timing
goTime1 = millis();
}
}
//*******************************
} //END of loop()
//******************************************************************************
void functionGo1()
{
valOne = digitalRead(triggerPin);
if (myVar == false && valOne == HIGH)
{
time = millis();
myVar = true;
}
} //END of functionGo1()
//******************************************************************************
unsigned long goTime1, goTime2; // NEEDS TO BE UNSIGNED LONG
goTime? Does that mean anything to you?
You don't seem to have a clue why the comment is true. You need to get one.
functionGo1();
That shows a complete lack of imagination. The function does something. The name should reflect that something. We should NOT have to guess what a function does.
valOne = digitalRead(triggerPin);
valOne? Come on. Use names that make sense. Something like triggerState, maybe.
The code does something. You forgot to explain what it actually does.
You expect the code to do something. You forgot to explain what you expected it to do.
The poor man's DAC I put in seems to work well when used on it's own, but not with the data collection sketch.
Seems to? It either does or it doesn't.
Seems to not work? It either doesn't or it does. You can't disguise that.
unsigned long goTime1, goTime2; // NEEDS TO BE UNSIGNED LONG
goTime? Does that mean anything to you?
You don't seem to have a clue why the comment is true. You need to get one.
functionGo1();
That shows a complete lack of imagination. The function does something. The name should reflect that something. We should NOT have to guess what a function does.
valOne = digitalRead(triggerPin);
valOne? Come on. Use names that make sense. Something like triggerState, maybe.
The code does something. You forgot to explain what it actually does.
You expect the code to do something. You forgot to explain what you expected it to do.
Seems to? It either does or it doesn't.
Seems to not work? It either doesn't or it does. You can't disguise that.
Details are seriously lacking.
Why not on the UNO?
The DAC does work. Sorry, "seems" wasn't the right word to use. When I uploaded a basic sketch to make it loop up to a certain value/temp, and go down to a certain value/temp, it works.
I changed the code to make it more up to your standards. Some of the stuff that is in there is left behind from when I was attempting this with delays instead of millis()
#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;
int nextTime1 = 50; // How long the button has to be pressed?
int nextTime2 = 60000;
unsigned long goTime1, goTime2; // time in milliseconds when we need to do the next operation
int16_t rawADCvalue;
float scalefactor = 0.1875F;
float volts = 0.0;
unsigned long time;
boolean triggerValue = 0;
int triggerPin = 8;
int Pwm = 9;
int Pwm_Value = 20;
bool myVar = false;
//******************************************************************************
void setup()
{
pinMode(triggerPin, INPUT);
pinMode(Pwm, OUTPUT); // set pin to output
Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
Serial.begin(115200); // Baud rate, either 115200 or 9600 works
ads.begin();
} //END of setup()
//******************************************************************************
void loop()
{
if (millis() - goTime1 >= nextTime1)
{
goTime1 = millis();
functionADCcollect();
}
//*******************************
if (myVar == true)
{
if (millis() - time < 10000UL)
{
rawADCvalue = ads.readADC_Differential_0_1();
volts = (rawADCvalue * scalefactor) / 1000.0;
Serial.print("Raw ADC Value = ");
Serial.print(rawADCvalue);
Serial.print("\tVoltage Measured = ");
Serial.println(volts, 6);
Serial.println();
}
else
{
myVar = false; //we are now finished with timing
goTime1 = millis();
}
}
//*******************************
} //END of loop()
//******************************************************************************
void functionADCcollect()
{
triggerValue = digitalRead(triggerPin); // Check to see if button has been pressed (5V)
if (myVar == false && triggerValue == HIGH)
{
time = millis();
myVar = true;
}
} //END of functionADCcollect()
//******************************************************************************
Because there is a range of values that an int can hold. The range differs depending on which computer the int is defined on. On a UNO, the range is -32768 to 32767. 60000 is NOT in that range.
functionADCcollect();
Is there something other than a function that you might be trying to call? The value that triggers this function call did NOT come from functionMillis(). It came from millis().
You still have not explained what the code actually does. You still have not explained what you expect it to do.
PaulS:
Because there is a range of values that an int can hold. The range differs depending on which computer the int is defined on. On a UNO, the range is -32768 to 32767. 60000 is NOT in that range.
functionADCcollect();
Is there something other than a function that you might be trying to call? The value that triggers this function call did NOT come from functionMillis(). It came from millis().
You still have not explained what the code actually does. You still have not explained what you expect it to do.
I thought you wanted help. I guess not.
I do want help. This just seems like a hard project, so please forgive me for coming off as ignorant on the subject.
The current code that I posted above does the following:
1: when a button is pressed voltage is collected through the differential ports on the ADS1115
2: the data is collected for 10000ms
3: after this time data stops collecting.
What I wish to implement alongside this is as follows:
1: when the same button is pressed voltage is sent from a PWM pin through the dac to an external heat board where 10mV = 10*C
2: Control the the voltage that is sent by the PWM
I do not know where to begin with what I wish to implement alongside my current code, and was just hoping for some suggestions and places to start learning.
1: when the same button is pressed voltage is sent from a PWM pin through the dac to an external heat board where 10mV = 10*C
When the same switch is pressed a second time? Or after the 10 second collection window when it is pressed the first time?
You really should study the state change detection example.
2: Control the the voltage that is sent by the PWM
You control the voltage output by the PWM pin by choosing a 3.3V device or a 5V device. Aside from that, you can only control the on/off frequency and the duty cycle (the proportion of the time that the pin is HIGH).
PaulS:
When the same switch is pressed a second time? Or after the 10 second collection window when it is pressed the first time?
You really should study the state change detection example.
You control the voltage output by the PWM pin by choosing a 3.3V device or a 5V device. Aside from that, you can only control the on/off frequency and the duty cycle (the proportion of the time that the pin is HIGH).
I was hoping it would be when the switch is pressed both functions would run. Which in certain iterations of my code it does.
I will look at the state change detection example
I was under the impression that with a low pass filter and a DAC you can convert a the duty cycle into a desired DAC voltage
I was under the impression that with a low pass filter and a DAC you can convert a the duty cycle into a desired DAC voltage
The output of an external circuit and the output of the Arduino are not the same thing. I had assumed that you were talking about the Arduino's output.
PaulS:
The output of an external circuit and the output of the Arduino are not the same thing. I had assumed that you were talking about the Arduino's output.
I am talking about controlling the output of the Arduino's PWM.
PaulS:
You have described what you want the external circuit's output to be. You have not described what you want the Arduino's output to be.
You have said that you want to:and that you can NOT do. The voltage will be 0V or 5V. Period. Unless you have a 3.3V board, in which case the voltage will be 0V or 3.3V. Period.
From my understanding and experimentation that is not true. With the DAC/RC you can make the duty cycle equal to a certain output voltage.
In a lot of situations, a PWM value of 50% will give an output that works like 50% of your input voltage. Paul is trying to educate you because this does not work in every situation and using words like "voltage" when you aren't using a voltage makes it harder for anyone else to understand you.
You are making an oven with (eventually) a controlled temperature profile? Did you search for any similar projects? There must be 100. Maybe 10 of those are good examples to copy.
For the ultimate in oven control with Arduino, look at the Controleo3 from Whizoo.
An RC filter on a PWM output is not a DAC, nor is it an approximation of one. The output voltage you measure will not be constant and for a constant PWM duty cycle, will depend entirely on the load resistance.
An Arduino PWM output is suitable for controlling the power output of a resistance heater, which will be roughly proportional to the PWM duty cycle. Lots of people have successfully done this, so do some web searches. A search phrase might be "arduino pwm heater control" (or light control).
But you will avoid a lot of frustration if you start with simpler projects or the built in examples, to learn the language and the special features of the Arduino.
MorganS:
In a lot of situations, a PWM value of 50% will give an output that works like 50% of your input voltage. Paul is trying to educate you because this does not work in every situation and using words like "voltage" when you aren't using a voltage makes it harder for anyone else to understand you.
You are making an oven with (eventually) a controlled temperature profile? Did you search for any similar projects? There must be 100. Maybe 10 of those are good examples to copy.
For the ultimate in oven control with Arduino, look at the Controleo3 from Whizoo.
Yes that is what I eventually am trying to make. I did search for similar projects, but didn't find any that were relevant enough.