Using two Arduino Mega boards to control 64 LEDs - arduino

I am a beginner in Arduino. I would like to control 64 LEDs using 2 Arduino Mega boards.
The logic is:
Arduino 1 blinks the LED in serial ===>
Arduino 1 finished blinking and sends the signal (HIGH) to Arduino 2 ===>
Arduino 2 blinks the LED in serial ===>
Arduino 2 finishes blinking and sends a signal (HIGH) to Arduino 1, and both Arduinos reset using asm volatile("jmp 0").
I am using pin 52 as TX and pin 53 as RX for both.
And now the problem is that after Arduino 1 finishes blinking and sends out the signal (HIGH) to Arduino 2, it doesn't wait for the signal from Arduino 2 but resets itself.
Can anyone have a look of my code to see whether it is a logical mistake or a coding error?
digitalWrite(TX, HIGH);
delay(1000);
if(digitalRead(RX)==HIGH) {
asm volatile("jmp 0");
}

digitalWrite(TX, HIGH);
delay(1000);
if(digitalRead(RX)==HIGH) {
asm volatile("jmp 0");
}
When you do this, you have to make sure that Arduino 2 sets its TX pin to LOW first, before playing with the LEDs. Only when it is finished, will should it set its TX pin to HIGH.

You need to interlock the shutdown sequence:
// Arduino 1:
digitalWrite(TX, HIGH); // set high for 1 second
delay(1000);
while (digitalRead(RX)) // wait for a low pulse from # 2
;
digitalWrite(TX, LOW); // #2 is latched.
while (!digitalRead(RX))
;
// RX is high again, #2 is ready to reset as well...
asm volatile("jmp 0");
// arduino # 2, assuming you have already detected a pulse longer than 500ms on RX,
// sequence:
digitalWrite(TX, LOW); // indicate we're latched
while(digitalRead(RX)) // wait for end of pulse from #1
;
digitalWrite(TX, HIGH); // indicate we're ready
delay(2); // make sure #1 gets it.
asm volatile("jmp 0"); // reset at approx same time as #1
Arduino #2 should keep its TX line HIGH while it's busy and wants to delay the reset.

Related

Issue on Verification error , first mismatch at type 0x0000

I am beginner in arduino. Here I tried to burn/upload a code from arduino IDE. Code executes successfully but problem is on uploading time. It shows Verification error , first mismatch at type 0x0000. 0x62 !=0x0c. I am trying to burn it from windows pc. Here is my code
int trigPin = 11; // Trigger
int echoPin = 12; // Echo
long duration, cm, inches;
void setup() {
Serial.begin (9600);
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// Convert the time into a distance
cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343
inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(250);
}
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino
Uno" Sketch uses 444 bytes (1%) of program storage space. Maximum is
32256 bytes. Global variables use 9 bytes (0%) of dynamic memory,
leaving 2039 bytes for local variables. Maximum is 2048 bytes. An
error occurred while uploading the sketch avrdude: verification error,
first mismatch at byte 0x0000 0x62 != 0x0c avrdude: verification
error; content mismatch #Piglet thanks for advice . Here is error
details
There are plenty of posts online about that error. You should be able to find them as well.
The most suggested solution is to burn the bootloader as in this post:
https://forum.arduino.cc/index.php?topic=453997.0
The bootloader is a small program that is on the Arduino Unos microcontroller. It is necessary to get your application on the the microcontroller via the USB interface.
You would need a IPS programmer otherwise.
To burn the bootloader you need a dedicated AVR ISP programmer or a second Arduino. You can get them for little money online.

DS1302 RTC board weird outputs on Arduino's Serial monitor

I have a DS1302 RTC board (Waveshare) connected to an Arduino uno.
I'm printing time to Arduino's Serial Monitor but I get weird numbers/characters, and after 2-4 seconds it stops printing.
Wiring:
Vcc -> 5v
GND -> GND
I/O (MISO) -> Pin 12
SCLK -> Pin 13
CE (CS) -> Pin 10
Library used: VirtuabotixRTC library.
Things I've tried so far:
I tried a second DS1302 RTC board.
I tried a different Arduino board.
I tried changing the jumper wires.
I tried different baud rates.
Code:
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC(7,8,9);
void setup() {
Serial.begin(9600);
// myRTC.setDS1302Time(30,30,5,5,5,5,2020);
}
void loop() {
myRTC.updateTime();
Serial.print(myRTC.hours);
Serial.print(":");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);
}
Screenshots:

Blinking an LED linked through Arduino-Python

I wrote a sample code for blinking an LED linked to Python. The code is not throwing me any error, but the LED is not blinking. Any suggestions?
Python code:
import serial #import the pyserial library
connected = False #this will represent whether or not ardunio is connected to the system
ser = serial.Serial("COM3",9600) #open the serial port on which Ardunio is connected to, this will coommunicate to the serial port where ardunio is connected, the number which is there is called baud rate, this will provide the speed at which the communication happens
while not connected:#you have to loop until the ardunio gets ready, now when the ardunio gets ready, blink the led in the ardunio
serin = ser.read()
connected = True
ser.write('1') #this will blink the led in the ardunio
while ser.read() == '1': #now once the led blinks, the ardunio gets message back from the serial port and it get freed from the loop!
ser.read()
print('Program is done')
ser.close()
Arduino code:
void setup() {
Serial.begin(9600);
pinMode(10,OUTPUT);
Serial.write('1');
}
void loop() {
if(Serial.available()>0){
digitalWrite(255,HIGH);
delay(50);
digitalWrite(50,LOW);
delay(50);
digitalWrite(255,HIGH);
delay(50);
digitalWrite(50,LOW);
delay(50);
digitalWrite(255,HIGH);
delay(50);
digitalWrite(50,LOW);
Serial.read();
}
else{
Serial.available()==0;
}
}
In the arduino code, you call
digitalWrite(50,LOW);
and
digitalWrite(255,HIGH);
but the first parameter of digitalWrite is the pin number, which you defined as pin 10. Simply change 50 and 255 to 10 as that is where you want your low and high signals to output to.

Can't connect Arduino to RFID

I am using an A-Star 32U4 Micro Arduino and I'm trying to connect the RDM6300 - 125KHz Cardreader Mini-Module.
I'm using this sketch at the moment:
#include <SoftwareSerial.h>
// RFID | Nano
// Pin 1 | D2
// Pin 2 | D3
SoftwareSerial Rfid = SoftwareSerial(2,3);
void setup() {
// Serial Monitor to see results on the computer
Serial.begin(9600);
// Communication to the RFID reader
Rfid.begin(9600);
}
void loop() {
// check, if any data is available
if(Rfid.available() > 0 ){
// as long as there is data available...
while(Rfid.available() > 0 ){
// read a byte
int r = Rfid.read();
// print it to the serial monitor
Serial.print(r, DEC);
Serial.print(" ");
}
// linebreak
Serial.println();
}
}
With this circuit:
module TX --- Arduino pin 2
module VCC ----- 5v
module ground ---- ground
antenna pins ---- antenna
When I put the card in the sensor nothing shows up on serial port. I tried this setup and the exact same sensors on an Arduino Uno (same sketch) and it worked perfectly, but I cant get this working on the Micro.
Arduino UNO and Micro uses different processors, though they work fairly similarly, they are not totaly identical.
It seams that
not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
From the SoftwareSerial Library description ( https://www.arduino.cc/en/Reference/softwareSerial )
Change the module TX from pin 2 to pin 8. and you should be good. :-)

Receive XBee signals on Arduino

Side A:
Arduino Uno R3 with Wireless Proto shield powered with USB
With XBee Pro S1, DH 0 DL FFFF MY 0 API 0
Wireless Proto shield has the serial select switch on the 'micro' position
side B:
XBee Explorer USB connected to a PC with XCTU software
With XBee Pro S1, DH 0 DL FFFF MY 0 API 0
(When I put both XBee modules in the USB explorer boards, connected with two PC's, I can send data back and forth without any problems, so I reckon the XBee settings are good.)
The Problem
Now I want the Arduino to capture the input from the B side (send with the XCTU terminal), but when I type anything in the terminal, the RSSI LED on side A just turns on for 5 seconds, but the Arduino does not seem to capture any data since it does not send data back like it should (Serial.print("I received: ");
Arduino sketch:
int incomingByte = 0;
void setup() {
Serial.begin(19200); //Both XBee chips are configured at 19200 Baud
Serial.print("start echo machine"); //This is received just fine on the B side
}
void loop() {
if (Serial.available() > 0) {
// Read the incoming byte:
incomingByte = Serial.read();
// Say what you got:
Serial.print("I received: "); //This never shows on the B-side
Serial.println(incomingByte, DEC);
}
}
How do I fix this problem?
You have to use a SoftwareSerial(RX,TX) for the XBee and the Serial for printing the output into the pc.
RX and TX of SoftwareSerial must be linked to the DOUT and DIN pin of the module into the Wireless Proto shield:
#include <SoftwareSerial.h>
// Connect pin 10 of Arduino to DOUT of Wireless Proto shield
uint8_t ssRX = 10;
// Connect pin 11 of Arduino to DIN of Wireless Proto shield
uint8_t ssTX = 11;
SoftwareSerial nss(ssRX, ssTX);
void setup() {
Serial.begin(19200);
nss.begin(19200);
Serial.println("Serial works");
}
void loop() {
if (nss.available()){
Serial.println("received packet:");
for(int i=0;i<25;i++){
Serial.print(nss.read(),HEX);
Serial.print(",");
}
Serial.println();
}
Many of the boards require the pull-up resistor on DIN to be enabled.
According to some sources this pull-up is enabled by default on the Digi Xbee module.
To ensure it is enabled or to enable it:
Put your Xbee module in a USB explorer and use X-CTU to check the PR configuration.
DIN is on bit 7 for the Xbee Pro S1, so in that case you need the last bit to be 1.
I put it like this: 00000001
Than you convert it to hex (01 in my case) and write that value to the Xbee module with X-CTU.
So it is an electronics issue and not a programming issue.

Resources