Hello
I have Arduino Leonardo, Adafruit Iduino TF028 display and ADC: MCP3424.
MCP342x.h correctly supports MCP3424.
When the display and ADC work separately - it is OK.
When I connect these two devices on the Arduino platform - ADC works and sends the measurement to Serial Monitor.
Adafruit Iduino TF028 display is frozen (on the display has frames and texts). Additionally, the touch screen of this display works correctly.
Adafruit Iduino TF028 and ADC do not use the same pins. ADC needs only +5V, 0, SCL, SDA to work - there is no hardware conflict
#include <Wire.h>
#include <MCP342x.h>
/* Demonstrate the use of convertAndRead().
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
#include <MCUFRIEND_kbv.h>
#include <OneWire.h>
long Voltage[4];
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define TS_MINX 100
#define TS_MAXX 920
#define TS_MINY 70
#define TS_MAXY 900
// optiona
#define LCD_RESET A4
#define BOXSIZE 40
#define PENRADIUS 3
#define MINPRESSURE 10
#define MAXPRESSURE 1000
MCUFRIEND_kbv tft;
MCP342x MCP = MCP342x(0x68);
void setup(void)
{
Serial.begin(9600);
Wire.begin();
// Enable power for MCP342x (needed for FL100 shield only)
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
// Reset devices
MCP342x::generalCallReset();
delay(1); // MC342x needs 300us to settle, wait 1ms
// Check device present
Wire.requestFrom(address, (uint8_t)1);
if (!Wire.available()) {
Serial.print("No device found at address ");
Serial.println(address, HEX);
while (1)
;
}
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.drawLine(0, 0, 0, 120, BLACK);
tft.setCursor(0, 60);
tft.drawRect(0, 0, 160, 125, WHITE); tft.setCursor(48, 48); tft.setTextColor(WHITE); tft.setTextSize(4); tft.print("CH1");
tft.drawRect(160, 0,159, 125, WHITE); tft.setCursor(208,48); tft.setTextColor(BLUE); tft.setTextSize(4); tft.print("CH2");
tft.drawRect(0, 125, 160, 114, WHITE); tft.setCursor(48, 158); tft.setTextColor(WHITE); tft.setTextSize(4); tft.print("CH3");
tft.drawRect(160, 125, 159, 114, RED); tft.setCursor(208,158); tft.setTextColor(RED); tft.setTextSize(4); tft.print("CH4");
Serial.begin(9600);
}
void loop(void)
{
long value = 0;
MCP342x::Config status;
// Initiate a conversion; convertAndRead() will wait until it can be read
uint8_t err = adc.convertAndRead(MCP342x::channel1, MCP342x::oneShot,
MCP342x::resolution16, MCP342x::gain1,
1000000, value, status);
if (err) {
Serial.print("Convert error: ");
Serial.println(err);
}
else {
Serial.print("Value: ");
Serial.println(value);
}
delay(1000);
}