@defragster - @manitou
Don't think there is anything else we can do to check freqCount. As far as I can tell its working like its suppose to. At some point have to look at the PWM code to see about implementing your post ##3973
#define MIN_LAG 1
#define MAX_LAG 21
#define N_LAGS (MAX_LAG-MIN_LAG+1)
#define NBUFFERS 7
#define S(a) ((long)(((a)-RawBufferPtr)/16))
float RawBuffer[16*1000*NBUFFERS];
float *RawBufferPtr = RawBuffer;
float *RawBufferEnd = RawBuffer + 16*1000*NBUFFERS;
long RawBufferIndex = 1;
///////////////////////////////////////////////////////////////////////////////
double Autocorrelation (int bufIndex, int channel) {
int i, rsum = 0;
float *p, *q;
double dot = 0;
p = RawBufferPtr + bufIndex*16000 - 16 + channel; // channel of most recent sample row
q = p - 16*MIN_LAG;
for (i = 0; i < N_LAGS; i++, q-=16) {
rsum += *q;
}
if (bufIndex >= 5) { // one piece
for (i = 0; i < 5000-MAX_LAG-1; i++, p-=16, q-=16) {
dot += rsum * p[0];
rsum += q[0]-q[16*N_LAGS];
}
dot += rsum * p[0];
} else { // 2 pieces + seam
for (i = 0; i < bufIndex*1000-MAX_LAG-1; i++, p-=16, q-=16) { // low part
dot += rsum * p[0];
rsum += q[0]-q[16*N_LAGS];
}
dot += rsum * p[0];
p -= 16;
// Serial.print( "dot ");Serial.print(dot);
q = RawBufferEnd - 16 + channel;
for (i= 0; i < N_LAGS-1; i++, p-=16, q-=16) { // seam part 1
rsum += q[0] - p[16*(-MIN_LAG)];
dot += rsum * p[0];
}
for (i= 0; i < MIN_LAG; i++, p-=16, q-=16) { // seam part 2
rsum += q[0] - q[16*(N_LAGS-1)];
dot += rsum * p[0];
}
p = RawBufferEnd - 16 + channel;
for (i = 0; i < (5-bufIndex)*1000-MAX_LAG; i++, p-=16, q-=16) { // high part
rsum += q[0]-q[16*(N_LAGS-1)];
dot += rsum * p[0];
}
}
return dot * (1./5000.);
}
///////////////////////////////////////////////////////////////////////////////
double MutualInformation (float RawBufferIndex, int ch1, int ch2) {
int i, j;
double sum;
float P1[16], P2[16];
int d1[16], d2[16], jd[16*16];
int *ip = jd;
long rbi16 = RawBufferIndex*1600;
float *p1 = RawBufferPtr + rbi16 - 16 + ch1; // ch1 of last sample row
float *p2 = RawBufferPtr + rbi16 - 16 + ch2; // ch2 of last sample row
#define R5000 (1./5000.)
for (i = 0; i < 16; i++) { // clear histograms
d1[i] = d2[i] = 0;
for (j = 0; j < 16; j++) {
*ip++ = 0;
}
}
for(i= 0; i < 5; i++) { // create joint and marginal dstributions
for (j = 0; j < 1000; j++) {
int i1 = *p1;
int i2 = *p2;
int b1 = (i1 >> 7) + 16; // scale +-1023 to 0..15
int b2 = (i2 >> 7) + 16;
if (b1 > 15) b1 = 0; else if (b1 < 0) b1 = 0;
if (b2 > 15) b2 = 0; else if (b2 < 0) b2 = 0;
d1[b1]++;
d2[b2]++;
jd[b1 + (b2<<4)]++;
p1 -= 16;
p2 -= 16;
}
if (p1 < RawBufferPtr) {
p1 += 16000*NBUFFERS;
p2 += 16000*NBUFFERS;
}
}
for (i = 0; i < 16; i++) { // compute marginal probablities
P1[i] = d1[i] * R5000;
P2[i] = d2[i] * R5000;
}
sum = 0;
for (i = 0; i < 16; i++) { // compute mutual information
for (j = 0; j < 16; j++) {
int i12 = i + (j<<4);
float P12 = jd[i12] * R5000;
if (P12 > 0) sum -= P12 * log(P12/(P1[i]*P2[j]));
}
}
return -sum;
}
//////////////////////////////////////////////////////
void setup() {
Serial.begin(57600);
for (int i = 0; i < 16*1000*NBUFFERS; i++) {
RawBuffer[i] = rand();
}
}
//////////////////////////////////////////////////////
void loop() {
int ta, tb, dt, t0, t1, t2;
int i, rbi, j, k;
ta = millis();
tb = millis();
dt = tb-ta;
t0 = millis();
i = 0;
rbi = 5;
for (k = 0; k < 100; k++)
for (j = 0; j < 16; j++) {
float c = Autocorrelation (rbi, j);
}
t1 = millis();
for (k = 0; k < 1; k++)
for (j = 0; j < 16; j++) {
float m = MutualInformation (rbi, i, j);
}
t2 = millis();
Serial.print ("t0 ");Serial.print(t0);Serial.print(", t1 ");Serial.print(t1);Serial.print(", t2 ");Serial.println(t2);
Serial.print ("Autocorrelation "); Serial.print(t1-t0-dt);
Serial.print (" ms, Mutual Information "); Serial.print(t2-t1-dt);
Serial.println (" ms");
}
Not sure where to post this.
This sketch bricked two brand new T4s.
// ...
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 4000 );
Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
pinMode( LED_BUILTIN, OUTPUT );
digitalWriteFast( LED_BUILTIN, HIGH );
delay (500 );
digitalWriteFast( LED_BUILTIN, LOW );
delay (500 );
digitalWriteFast( LED_BUILTIN, HIGH );
delay (500 );
digitalWriteFast( LED_BUILTIN, LOW );
delay (500 );
for (int i = 0; i < 16 * 1000 * NBUFFERS; i++) {
RawBuffer[i] = rand();
}
digitalWriteFast( LED_BUILTIN, HIGH );
delay (500 );
Serial.println("\n" __FILE__ " -SECOND in Setup" );
delay(200);
}
----------------------------------------There is a process to recover the T4 - if it really seems to be bricked.
> USB CABLE plugged in for POWER
> With the USB end in view to see the RED Bootloader LED
> Press the Teensy program Button and hold it continuously for 15 seconds ... until the RED LED flashes
> Release the Program button when the RED Led Flashes
> Watch the RED LED go FULL on for 10-15 seconds as it factory resets the T4
>> T4 should now power up with simple BLINK on LED and no USB output as a RawHID device.
If that doesn't work then after trying again - indicate what was observed.
Question: Sketch only - nothing soldered to the T4's?
Spoke too soon. Macbook doesn't see them on any port.
"No Teensy boards were found on any USB ports of your computer."
00:35:55.917 -> FF
00:35:55.917 -> FF
00:35:57.837 -> Test1 (S/B 0xAA): FF
00:35:57.837 -> Test1 (S/B 0x55: FF
00:35:58.846 -> Revision: FF
00:35:59.853 -> FF
00:35:59.853 -> FF
00:36:01.834 -> Test1 (S/B 0xAA): FF
00:36:01.834 -> Test1 (S/B 0x55: FF
00:36:02.844 -> Revision: FF
00:36:03.849 -> FF
00:36:03.849 -> FF
00:36:05.855 -> Test1 (S/B 0xAA): FF
00:36:05.855 -> Test1 (S/B 0x55: FF
00:36:06.833 -> Revision: FF
00:36:07.836 -> FF
00:36:07.836 -> FF
Hello mjs513,
I received my 2MP camera today.
In trying the ArduCAM_Mini_2MP_Plus_functions example, I am getting the error:
00:32:04.227 -> ACK CMD SPI interface Error! END
In trying the ArduCAM_SPI_BUS_TEST.ino example, I get the following:
Code:00:35:55.917 -> FF 00:35:55.917 -> FF 00:35:57.837 -> Test1 (S/B 0xAA): FF 00:35:57.837 -> Test1 (S/B 0x55: FF 00:35:58.846 -> Revision: FF 00:35:59.853 -> FF 00:35:59.853 -> FF 00:36:01.834 -> Test1 (S/B 0xAA): FF 00:36:01.834 -> Test1 (S/B 0x55: FF 00:36:02.844 -> Revision: FF 00:36:03.849 -> FF 00:36:03.849 -> FF 00:36:05.855 -> Test1 (S/B 0xAA): FF 00:36:05.855 -> Test1 (S/B 0x55: FF 00:36:06.833 -> Revision: FF 00:36:07.836 -> FF 00:36:07.836 -> FF
Is this the normal behavior?
Thanks in advance.
@jimmie
No that is not normal you should be seeing AA/55/Rev #. FF's are telling you that communication failed with SPI to the camera.
EDIT: 4. Make sure the CS_PIN in the sketches match what you connected the camera CS pin on the Arduino.
Also I just posted an update to the lib that hopefully improves the transfer speed of images.
Mike
myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
// ArduCAM demo (C)2013 Lee
// web: http://www.ArduCAM.com
// This program is a demo of how to communicate with camera modules
// via I2C interface and send read data back to Serial Monitor in Arduino IDE.
//
// This demo was made for Omnivision OV5642 sensor.
// 1. Receive commands from Serial Monitor
// 2. Read Product ID from OV5642 registers
// 3. Send back to Serial Monitor.
// This program requires the ArduCAM V3.0.0 (or above) library and Rev.C ArduCAM shield
// and use Arduino IDE 1.5.2 compiler
//#include <UTFT_SPI.h>
#include <SD.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <SPI.h>
#include "memorysaver.h"
// set pin 10 as the slave select for the ArduCAM shield:
const int SPI_CS = 10;
ArduCAM myCAM(OV2640, SPI_CS);
uint8_t vid,pid;
uint8_t temp;
void setup()
{
Wire.begin();
Serial.begin(115200);
Serial.println(F("ArduCAM Start!"));
// set the SPI_CS as an output:
pinMode(SPI_CS, OUTPUT);
digitalWrite(SPI_CS, HIGH);
// initialize SPI:
SPI.begin();
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
//Reset the CPLD
myCAM.write_reg(0x07, 0x80);
delay(100);
myCAM.write_reg(0x07, 0x00);
delay(100);
while(1){
//Check if the camera module type is OV2640
myCAM.wrSensorReg8_8(0xff, 0x01);
myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 ))){
Serial.println(F("Can't find OV2640 module!"));
delay(1000); continue;
}else{
Serial.println(F("OV2640 detected.")); break;
}
}
myCAM.set_format(JPEG);
myCAM.InitCAM();
}
void loop()
{
}
There is the ever popular question: have you added pull-up resistors or does your device have pull-up resistors? You would want one resistor between SCL and 3.3v, and another between SDA and 3.3v. Typically for a 3.3v system like Teensy LC, 3.x, 4.0, you would use 2.2K resistors if there are just a few devices on the bus and you use short wires to connect them. For 5v systems, 4.7K resistors tend to be favored. Note, using higher ohm resistors than you need, or having multiple pull-up resistors on the bus might mean high speed I2C setups would not work, and you would have to drop to a lower speed.@jimmie,
Sounds like your I2C connections are not correct - check that you have SDA going to pin 18 and SCL going to pin 19. Also I had to modify my I2C test sketch - forgot to add something.
Thank you. I uploaded your sketch and got "OV2640 detected.". I had not connected the i2c lines before thinking that it was operating as an SPI device.
Now both sketches are working. I can t wait until I add an SD card and start saving images .
Thanks again.
Hello Mjs513,
I have done some reading on the Arducam. In my project, I need to take a snapshot and then analyze a region for the most dominant color within that region. So basically read RGB values within a rectangle and average them.
Can this be done on board the Arducam? For processing speed, I do not want to save the image since I do not need the snapshot image. Rather, just the dominant color in a region ...
Thanks in advance for your input.