Hi All,
Strange issue with the Adafruit_MCP4725 library, after 714 times it locks up, does this every time!
Steve
#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
long count;
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
randomSeed(analogRead(0));
count =0;
}
void loop(void) {
uint16_t i;
i=1000;
Serial.println(count);
dac.begin(0x60);
dac.setVoltage(i,false);
delay(30);
dac.begin(0x61);
dac.setVoltage(i,false);
delay(30);
count++;
}
dlloyd
March 8, 2022, 3:45pm
2
Check if the supplied examples run OK.
Haven't used this library before, but after taking a quick look, it would seem reasonable to only run setVoltage
if DAC is found ...
#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
uint16_t count;
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
randomSeed(analogRead(0));
count = 0;
}
void loop(void) {
uint16_t i = 1000;
Serial.println(count);
if (dac.begin(0x60)) dac.setVoltage(i, false);
delay(30);
if (dac.begin(0x61)) dac.setVoltage(i, false);
delay(30);
count++;
}
If there's still an issue, perhaps the print buffer is getting swamped, then try increasing delay.
EDIT:
If you have several MCP4725s, then you should instantiate several objects ...
Adafruit_MCP4725 dac1;
Adafruit_MCP4725 dac2;
and rewrite your sketch accordingly. Now you can put dac1.begin
and dac2.begin
in setup to run only once.
Koepel
March 8, 2022, 4:32pm
3
The dac.begin() should be in the setup() and not in the loop(). I think it allocates memory. When doing that in the loop(), the heap crashes against the stack.
Koepel
March 8, 2022, 5:46pm
5
I looked into it, while it was already solved. That's not okay.
Hi All,
Strange issue with the Adafruit_MCP4725 library, after 714 times it locks up, does this every time!
#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
long count;
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
randomSeed(analogRead(0));
count =0;
}
void loop(void) {
uint16_t i;
i=1000;
Serial.println(count);
dac.begin(0x60);
dac.setVoltage(i,false);
delay(30);
dac.begin(0x61);
dac.setVoltage(i,false);
delay(30);
count++;
}
Steve
How do you know the code runs 714 iterations before stopping?
How may devices are you using? Why the two addresses. What does an i2c scanner show?
dac.begin() typically goes in setup.
I have two DACs. I don't have a scanner.
I know you normally use it in setup but I need to change address to access both chips, maybe this is the issue.
Steve
Because the serial output stops after 714 times, looks like this can vary but not by much.
Steve
scarr999:
dac.begin(0x60);
Lines like this usually belong in setup(). Why did you put them in loop()?
I don't have a scanner.
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#include <Wire.h>
void setup() {
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
delay(5000);
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
If you indeed have the two different addresses, then I think the code should look like this
#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac1;
Adafruit_MCP4725 dac2;
long count;
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
randomSeed(analogRead(0));
count =0;
dac1.begin(0x60);
dac2.begin(0x61);
}
void loop(void) {
uint16_t i;
i=1000;
Serial.println(count);
//dac.begin(0x60);
dac1.setVoltage(i,false);
delay(30);
//dac.begin(0x61);
dac2.setVoltage(i,false);
delay(30);
count++;
}
1 Like
Omg of course, wow how stupid, sorry guy and thx
system
Closed
August 31, 2022, 5:54pm
14
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.