I have two Arduino, one is to handle the Bluetooth communication and send a signal to the other Arduino, and the other to interpret the signal and display or hide an image on the E-ink display.
It work just fine when they both are connected through the USB. But when I connect a 9V battery to the Arduino running the E-ink, instead of the USB, the image is displayed and cleared (looping), as if the IF ELSE conditions are not there.
I have tested if it actually runs the method by adding delay to the showImg()-method, and that seems to work.
I have also tested with connecting the USB cable to the E-ink Arduino to a 5V charger, and the case is the same.
Bluetooth code:
int ledPin = 13;
int state = 0;
int flag = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
}
void loop() {
if(Serial.available() > 0){
state = Serial.read();
flag=0;
}
if (state == '2') {
digitalWrite(ledPin, LOW);
if(flag == 0){
Serial.println("Screen: off");
flag = 1;
}
}
else if (state == '1') {
digitalWrite(ledPin, HIGH);
if(flag == 0){
Serial.println("Screen: on");
flag = 1;
}
}
}
E-ink code:
#include <epd.h>
int displayed = 0;
int val = 0;
void showImg(void)
{
Serial.print("showImg");
displayed = 1;
//epd_clear();
epd_disp_bitmap("PIC9.bmp", 0, 100);
epd_udpate();
//delay(10000);
}
void clearImg(void){
Serial.print("clearImg");
displayed = 0;
epd_clear();
epd_udpate();
}
void setup(void)
{
//Serial.begin(9600);
epd_init();
epd_wakeup();
epd_set_memory(MEM_TF);
pinMode(7, INPUT);
}
void loop(void)
{
val = digitalRead(7);
if(val == 1){
if(displayed == 0){
showImg();
}
}else {
if(displayed == 1){
clearImg();
}
}
//Serial.println(val);
//delay(3000);
}
I am a beginner when it comes to Arduino, So I hope someone can give me some hints to what may be wrong.
Thanks!