DAC_MCP4725.ino 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. Description: Use DAC Unit DAC to output 0 ~ 3.3V voltage with an accuracy of 12 bits.
  3. Please install library before compiling:
  4. Adafruit MCP4725: https://github.com/adafruit/Adafruit_MCP4725
  5. */
  6. #include <Wire.h>
  7. #include <Adafruit_MCP4725.h>
  8. #include <M5Stack.h>
  9. #define DAC_ADDR
  10. Adafruit_MCP4725 dac;
  11. void setup(void) {
  12. M5.begin(true, false, false);
  13. M5.Power.begin();
  14. Serial.begin(115200);
  15. Serial.println("Hello!");
  16. M5.Lcd.setTextFont(4);
  17. M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
  18. M5.Lcd.drawString("DAC MCP4725 demo.",25, 100, 4);
  19. // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
  20. // For MCP4725A0 the address is 0x60 or 0x61
  21. // For MCP4725A2 the address is 0x64 or 0x65
  22. dac.begin(0x60);
  23. Serial.println("Generating a triangle wave");
  24. dac.setVoltage(2048, false);
  25. }
  26. void loop(void) {
  27. // 12bit value , false mean not write EEPROM
  28. dac.setVoltage(1024, false);
  29. delay(1000);
  30. dac.setVoltage(2048, false);
  31. delay(1000);
  32. }