Looking for a MEGA2560 DAC code

I am doing a sketch compiling which used Arduino UNO's DAC, but the Arduino don't have enough pins for my project, and I got good help here to use MEGA2560 mini. where can I find a MEGA2560 DAC code which I can replace Arduino's DAC?

The Arduino UNO's ATmega328P doesn't have a DAC (unless you count the successive-approximation ADC's DAC).

Please explain what you actually want to do.

1 Like

Sorry I messed it, what I need is MEGA2560 ADC NOT DAC.

What code do you use now?

1 Like

The ADCs in the ATmega2560 and the ATmega328P are really similar. What does your UNO code look like? What do you need help with?

1 Like

It is multi meter diy, was designed controller is Arduino nano, and I like to use a MEGA2560. it is a really long sketch, would you please ref. to this link please:

I doubt anyone is going to download that zip and plough through hundreds of lines of code to decipher what it does or what might cause issues on the ATmega2560.

If you want help, you'll have to post some context and specific questions here.

1 Like

The I2C pins are different between the Uno/Nano and the Mega2560. Instead of A4 and A5, SDA and SCL are pins 20 (SDA) and 21 (SCL) (or the SCL and SDA pins near pin 13 and ground).

1 Like

Did you move the OLED pins to the MEGA's I2C pins? They aren't Pin A4 and Pin A5 like on the UNO.

1 Like

I think that is it not possible.

The code was written for a few different Arduino boards, but then it was fixed to be used for a Uno or Nano only.
The code in that ZIP file is here: https://github.com/vlad-gheorghe/ardutester/blob/master/ardutester-i2c.ino.
On that Github is a link to a Russian forum and someone asks in 2016 if it can run on a Arduino Mega 2560. That problem was not solved.

Google Translate:

Question: Is it possible to convert a fresh version of the 1.12k sources into a sketch? There is an ArduinoMega2560 with a bootloader on the CH340.
Answer: I have already converted the 1.12k version of the source code to the sketch. It compiles successfully, but so far refuses to measure. Writes "No, unknown, or damaged part" to any components. There is more code there and in what place I have not yet found what needs to be changed.

There is a lot direct register access, and those might be slightly different for a Arduino Mega 2560 board.

This is just a small piece that needs to be adjusted:

#define ADC_DDR DDRC
#define ADC_PIN PINC
#define TP1 0
#define TP2 1
#define TP3 2
#define TPext 3
// Port pin for 2.5V precision reference used for VCC check (optional)
#define TPREF 4
// Port pin for Battery voltage measuring
#define TPBAT 5

But there is more throughout the whole sketch.

1 Like

A code found online that is too large to post.

Its strange, maybe the Proteus model wrong?
The attached is a very simple code, the simulation didn't show.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);


void loop() 
  display.println("Subscribe Now!");


I did the right connection. Both Arduiion UNO & MEGA2560 got nothing on Proteus simulation.

Thank you for your nice work.
It is the situation like you side when I made my post. But I found another link from [plouc68000] that said this DIY works for UNO & MEGA. and I did test the newer code with relative wiring changes. No improve yet.
Newer Version:

The reason I am looking for the MEGA's ADC, is the MEGA code's config also asked wiring the analog pins to A0-A3, I guess the MEGA has A0-A7 ADC? may same as Arduino? if they are same I don't need modify the code, otherwise I need.

Also, the new file included total 60 files, can I add another 15 more?

Mega has A0 - A15. Uno has A0 - A5.

1 Like

Is that means if I wired A0-A5 , I don't need modify the code and directly use?
Does MEGA2560 has more than 1 ADC? because I do have another part need ADC too.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.