i need using OV7670 camera on my arduino mega, and i found this site have tutorial using ov7670 camera, but in this tutorial they use arduino Uno. if i'm using arduino Mega2560, what i need to do? do i have to change their code and pin connection ?
here is the link
https://www.instructables.com/id/OV7670-Arduino-Camera-Sensor-Module-Framecapture-T/?amp_page=true
1 Answer 1
Yes, you will have to change the code to match the Mega pinout.
Because the program need to run quite fast, and the Arduino functions
digitalRead()
and digitalWrite()
are dead slow, the author of the
program used direct port access for performing the raw IO.
For example:
//Wait for vsync it is on pin 3 (counting from 0) portD
while(!(PIND&8));//wait for high
while((PIND&8));//wait for low
This is testing pin PD3 (8 is 23), which on the Uno is digital 3, but on the Mega is digital 18. The same code could be written in a portable fashion:
//Wait for vsync it is on pin 3 (counting from 0) portD
while (digitalRead(3) == LOW); //wait for high
while (digitalRead(3) == HIGH); //wait for low
but it would probably be too slow.
Note also that here:
UDR0=(PINC&15)|(PIND&240);
the program takes advantage of the particular pin mapping of the Uno in
order to read 8 inputs with only two port reads (4 bits on
port C and 4 bits on port D). You could do even better on the Mega
if you use pins A8 through A15 for the data bus, and then read the whole
8-bit word as PINK
.
There may be some other differences between the Uno and the Mega that need to be taken into account, but the pin mapping is the only one that is obvious to me just by quickly going through the code.
-
hello, you said that "..which on the Uno is digital 3, but on the Mega is digital 18." how do you know on the Mega is Digital Pin 18? and i still don't understand about use pins A8 through A15 and read the word as PINKIbnum Richaflor– Ibnum Richaflor2019年09月10日 03:47:18 +00:00Commented Sep 10, 2019 at 3:47
-
@IbnumRichaflor: Re "how do you know [...]": Google "Arduino Uno pinout" and "Arduino Mega pinout". Re "use pins A8 through A15 and read the word as PINK": Pins A8 – A15 (Arduino labeling) are PK0 – PK7 (manufacturer's labeling), collectively known as "port K".Edgar Bonet– Edgar Bonet2019年09月10日 07:35:40 +00:00Commented Sep 10, 2019 at 7:35