Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino lepton_command SET commands not working? #5

Open
adgriff2 opened this issue Oct 6, 2014 · 14 comments
Open

Arduino lepton_command SET commands not working? #5

adgriff2 opened this issue Oct 6, 2014 · 14 comments

Comments

@adgriff2
Copy link
Contributor

adgriff2 commented Oct 6, 2014

Running

  Serial.println("AGC READ");
  lepton_command(AGC, 0x00  , GET);
  read_data();

both before and after

agc_enable();

yields the same response.

lepton_command(AGC, 0x00  , SET);

also has no effect.

The Lepton Software Interface Description Document relies heavily on the SDK doing everything for you. It isn't clear to me exactly how you give the lepton the values you want to set. It doesn't seem to be a part of the command. I first thought you didn't need to send anything other than the command -- it would maybe toggle it -- but that doesn't seem to be happening.

The flowchart for Host Write Attribute on page 11 seems to say you must write what you want to 'SET' into the data registers and set the length register prior to writing the SET command, but what 16 bits should I send? 0xffff to turn on and 0x0000 to turn off?

I suppose I could reverse engineer the SDK, but it should be easier than that.

@PureEngineering
Copy link
Collaborator

here is something I found in the IDD document.
"AGC, VID, and SYS Module Command ID Generation
For commands within the AGC, VID, and SYS modules, the protection bit value is 0x0000 and the
command module ID, command ID, and command type depend on the desired action. For
example, to read the current AGC enable state, the AGC Module ID is 0x0100, the ACG Enable
command ID Base is 0x00, and a Get command type is 0x0. The Command ID is synthesized as
follows: Module ID + Command ID Base + Type + Protection Bit value= Command ID. So in this
example, 0x0100 + 0x00 + 0x0 + 0x0000 = 0x0100. To set the AGC enable state to enabled, the
command type is 0x1 and thus the Command ID is 0x100 + 0x00 + 0x1 + 0x0000 = 0x0101.
"

I think the arduino agc_enable is not correct.
Wire.write(0x01); > 0x00
Wire.write(0x05); > 0x01
Wire.write(0x00);
Wire.write(0x01);

@adgriff2
Copy link
Contributor Author

adgriff2 commented Oct 6, 2014

Right, I saw that as well. This is very confusing because on page 16 it says AGC module ID is B0001, then in your example it says the AGC SDK module is 0x100. I was assuming the 0x100 ID was only used in the SDK, but then it showed it being used in a raw calculation of the Command ID... so I'm confused.

@PureEngineering
Copy link
Collaborator

I was confused as well. I don't think I got it correct for writing only
reading. I'm going to have revisit the i2c writing and figure out what is
wrong.
On Oct 6, 2014 7:07 AM, "Adam Griffin" notifications@github.com wrote:

Right, I saw that as well. This is very confusing because on page 16 it
says AGC module ID is B0001, then in your example it says the AGC SDK
module is 0x100. I was assuming the 0x100 ID was only used in the SDK, but
then it showed it being used in a raw calculation of the Command ID... so
I'm confused.


Reply to this email directly or view it on GitHub
#5 (comment)
.

@adgriff2
Copy link
Contributor Author

adgriff2 commented Oct 9, 2014

I compiled and reverse engineered the SDK to see how it wrote commands. In so many words, the flow diagram on pg 11 of the LSIDD is generally correct, but exactly what needs to be written to the DATA registers isn't always clear.

Instead of having a generic lepton_command function for GETs and SETs, I think it may be best to have a lepton_get function for all GETs and a separate function for SETs because the SETs will need 2 more inputs, 'data' and 'data_length'. C++ and arduino is kinda raw for me, I'm a Matlab/C guy. I'm not sure if you can overload arduino functions.

Depending how much time I have to work on it, I'll try to have a patch proposed tomorrow night.

@mranostay
Copy link

Any update on this? Why aren't the DATA and DATA_LEN registers set in this function?

@adgriff2
Copy link
Contributor Author

Apologies for forgetting about this. I got a couple specific commands working and was trying to generalize it out to all commands, but got sidetracked. I'll try to upload my limited example after I get back home this weekend.

@mranostay
Copy link

So does it isn't as clearcut as writing to the data registers and sending
the command register the 0x100 command?

On Sat, Nov 29, 2014 at 11:42 AM, Adam Griffin notifications@github.com
wrote:

Apologies for forgetting about this. I got a couple specific commands
working and was trying to generalize it out to all commands, but got
sidetracked. I'll try to upload my limited example after I get back home
this weekend.


Reply to this email directly or view it on GitHub
#5 (comment)
.

@adgriff2
Copy link
Contributor Author

adgriff2 commented Dec 2, 2014

In general it is just as simple as sending, in this order, data to the data registers, data length to the data length register, and then the command to the command register. However, while it may be trivial to some people, the details of this were somewhat confusing to me until I ran through the official SDK to see what it was doing.

One confusing problem was that the register addresses and sizes are all 16bit, but Wire.write(); only writes single bytes. Another problem was translating the functions in the SDK to data_reg binary values. Finally, unless I misunderstood, several places in the SDK and software interface description document say the data_len register should be populated with the number of data registers written, but it actually needs to be the number of bytes written. (2x the number of written regs)

This function works (as of a month or two ago):

#define ADDRESS  (0x2A)
#define COMMANDID_REG (0x04)
#define DATALEN_REG (0x06)
#define DATA0 (0x08)
void agc_enable()
{
  byte error;
  Wire.beginTransmission(ADDRESS); // transmit to device #4
  //16bit data_reg address
  Wire.write(0x00);
  Wire.write(DATA0);
  //16bit command equivalent to SDK LEP_GetAgcEnableState()
  Wire.write(0x00);
  Wire.write(0x01);
  error = Wire.endTransmission();
  if (error != 0)
  {
    Serial.print("error=");
    Serial.println(error);
  }
  Wire.beginTransmission(ADDRESS);
  //16bit data_len address
  Wire.write(0x00);
  Wire.write(DATALEN_REG);
  //16bit value for number of bytes in data_regs (not number of regs)
  Wire.write(0x00);
  Wire.write(0x02);
  error = Wire.endTransmission();
  if (error != 0)
  {
    Serial.print("error=");
    Serial.println(error);
  }
  Wire.beginTransmission(ADDRESS);
  //16bit command_reg address
  Wire.write(0x00);
  Wire.write(COMMANDID_REG);
  //16bit module id of AGC (0x0100) binary AND with SET (0x01) and then split into 2 bytes (0x0101)
  Wire.write(0x01);
  Wire.write(0x01);
  error = Wire.endTransmission();
  if (error != 0)
  {
    Serial.print("error=");
    Serial.println(error);
  }
}

It seems intuitive that the AGC enable command is 1 and disable is 0, but what about more complicated commands? There are only 2 versions of output available in this version of lepton RAW14 (default) and RGB888. The command to switch to RGB888 is 0x0003 and the command to switch back to RAW14 is 0x0007. Turns out this is buried in an enum in the SDK. I was hoping to eventually have definitions for LEP_VIDEO_OUTPUT_FORMAT_RGB888, LEP_VIDEO_OUTPUT_FORMAT_RAW14 etc, but got ADD and switched projects.

Hopefully the function above can be adapted for whatever you need.

@wenyueqiang
Copy link

I just give the lepton 5V power and SCL and SDA signal ,can I read the data of status register

@Patrickyp
Copy link

Patrickyp commented Sep 22, 2016

How did you know what to write to the data register?

//16bit command equivalent to SDK LEP_GetAgcEnableState()
  Wire.write(0x00);
  Wire.write(0x01);

Isn't this a SET command not GET? But the code seems to work I am getting a none 0 value from agc read now.

@Patrickyp
Copy link

Nevermind I figured it out 0x01 is to enable AGC and 0x00 is to disable.

@wenyueqiang
Copy link

well,I use STM32 SPI to transfer the data,how can i idenftify then avilable
frame and avilable packets?

2016-09-23 9:24 GMT+08:00 Patrickyp notifications@github.com:

Nevermind I figured it out 0x01 is to enable AGC and 0x00 is to disable.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#5 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASUA9PsEF8V-vTnKE9F3SPXEHZHcDGOCks5qsypKgaJpZM4CrDjj
.

@dann109
Copy link

dann109 commented Nov 20, 2017

I made a function based on adgriff2's function for agc_enable and it worked well on a PIC32. I followed the procedure for RGB888 enable and found it is required to also set the OEM protection bit 0x4000. Obv this is done after AGC enable.
rgb888enabledatastream

@khaoulaMOS
Copy link

HELLO INEED your help i am using esp32 board and lepton breakout v1.4 i got this error could you please help me
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants