Teensy 4.0 First Beta Test

Status
Not open for further replies.
@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
 
@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

Based on prior page manitou posts - it seems the use of pin #18 wasn't helping :: "pins 8 and 23 are flexPWM and they can do 75mhz " and "T4 PWM, discrete PWM frequencies are 150mhz/2, 150/3, 150/4, 150/5 .... so 75mhz, 50mhz, 37.5 mhz, 30mhz, 25, 21.428,18.75 "

that tiny increment test was missing the boat when it came to presenting a usable test signal of known value.

Glad you looked at it - though as feared it was my trouble causing extra work.

Thanks @manitou
 
Since uncanny eyes seems to be discussed in various places, I see Adafruit is soon going to release a mask with 2 240x240 displays and code for their M4 processor (along with a 9 pin cable). If people are motivated, we might want to send the Teensy mods for this (obviously for the mask itself since it includes the M4 it wouldn't work, but it would be nice to get in code to the source for the 240x240 displays for T4 and T3.6/3.5):


I recall Lady Ada mentioning this board as coming in last week's Ask an Engineer. And now, there are pictures (but so far, it isn't available for sale).
 
Not sure where to post this.

This sketch bricked two brand new T4s.



Code:
#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");
}
 
Last edited by a moderator:
Not sure where to post this.

This sketch bricked two brand new T4s.
// ...

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?
 
Above post is the quick worst case answer and likely not needed.

What happens when the T4 is on USB abd the Program Button is pressed and released, i.e. not held? Does the bootloader RED led flash?

The code seems to be doing lots of memory access with pointers - and may have just trashed memory in a way the took the USB stack offline.

A press of the program button should flash the RED led and put the T4 into a state to be programmed.
 
Last edited:
Running that code it is trashing something - but the T4 is certainly not Bricked - just Offline for USB until a Button Press.

Changing the setup() code to this it will print to SerMon and toggle the LED when powered:
Code:
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);
}

It will then be hung entering loop and the USB will be offline.

Repowering the Teensy 4 will show that same situation over and over.

Pressing the Button will light the RED led and await programming structions fro the computer.

Then the CODE needs to be checked for out of bound pointer references or errors on counts or data types and sizes causing the code to trash memory. When that happens the USB Stack in this case is no longer functional and that is why the program Button is on the Teensy - to take it to bootloader state - or for disaster cases when it may have takedn a harder fault - that is the 15 second Restore noted in post #4081.
 
I ran it here too. Definitely makes the Teensy 4.0 stop communicating so you can't upload by clicking Upload in Arduino. But pressing the button on Teensy 4.0 still works fine.

Every Teensy, all the way back to Teensy 1.0, has a pushbutton dedicated to recovering from a "bad" program which disables the USB port or otherwise crashes in a way where USB communication no longer works.
 
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?
----------------------------------------

Sketch only, no pins, just a timing test.

Worked perfectly. Recoverd both of them.

Thanks much.
 
Program button gets the bootloader LED to flash and flicker for a bit.

Curious how I might have clobbered the USB state.

At least now I can do more than 5 experiments. :)
 
Spoke too soon. Macbook doesn't see them on any port.

"No Teensy boards were found on any USB ports of your computer."

That should change if pressing the Button Lights the RED LED. It should have the Teensy ready to load a working program - try a Simple Blink.
 
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.
 
Hi!

I was working on a Teensy 4.0 using the audio board with CS42448. There is a bug in an input_tdm.cpp file where serial data input is defined. It uses CORE_PIN7_CONFIG, but it should be CORE_PIN8_CONFIG.
 
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.

A couple of things to check.

1. Are the ArduCAM and UTFT4ArduCAM_SPI directories in your libraries directory, i.e.,
../…/libraries
|
|---ArduCAM
|
|---UTFT4ArduCAM_SPI

2. Double check your connections to the T4. Happens to me all the time.

3. Remember, VCC goes to 3.3v.

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
 
Last edited:
@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

Thank you very much. The CS pin was incorrect, I switched it to 10 (T4) and now it works.

================================

After I recompiled the ArduCAM_Mini_2MP_Plus_functions example, it never goes past the following statement:

Code:
myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
 
Last edited:
@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.

You can run this to check if your I2C connections are correct to the Camera:
Code:
// 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()
{
}
 
@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.
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.
 
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.
 
Thank you @MichaelMeissner. This is good advice. Indeed, I have a couple of devices that would not work without those resistors. In the case of the Arducam, apparently it has the resistors on board as the code from @mjs513 worked.
 
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.
 
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.

Not a problem. Glad you got it working. Good for me to know that it works for other users as well :)
 
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.

Sadly no - you can not do it within Arducam. You could write the sketch to save the region you are interested in to a array and then do your analysis for domninant color on the T4 itself. I think this is what you mean though after re-reading your question. If you look at the demo sketch it shows how its transmitting the image - basically as a row/column. Using that info you could store it for later use. Just be careful that you don't exceed memory limitations.

Mike

PS: Maybe we should start another thread on the Arducam. This is getting out of the realm of this thread :)
 
Thank you very much Mike. I appreciate your help and timely responses.

Yes indeed, this should go to a different thread. I will going forward.
 
Status
Not open for further replies.
Back
Top