imaginevision / Z-Camera-Doc

Document for Z Camera
149 stars 46 forks source link

Enabling UART mode #22

Open garciaanto opened 6 years ago

garciaanto commented 6 years ago

Hi, In the documentation is shown the address 0xa3 for the external eeprom must be used. I have implemented a kind of "sniffer" for the i2c and what I see is different:

- While booting the cam try to read the address 0x51 1 time
- After that is in a loop asking to read 0x48 

If I answer with the Byte 0x03 (uart mode) in the first query nothing is happens If I answer with 0x03 to all the queries the cam do not start, so its power on but nothing in the display (frame, layout...)

Any help?

skadiexe commented 6 years ago

0x51 is 0xA3 shifted 1 bit right. it is the same 7-bit adress. 1 or 0 in LSB means Read or Write while accessing eeprom

p.s. my camera do not have any activity on i2c overall, always logic 1 on SDA/SCL

RagnarJensen commented 6 years ago

I have it working on the bench, using a real 24C02B EEPROM at address 0x51. EEPROMs larger than 16Kbit cannot be used, because they use 2 byte addressing.

When the camera starts up, the first transaction on the i2c bus my logic analyzer sees is this: zcame1_bootup_uart The camera reads the first byte from device 0x51, which returns the value 3. Note that you don't get any visible reaction from the camera at this stage. It's not until you actually start to send it commands that it does something.

Then it enters a loop, continually reading from device 0x48, which is a temperature sensor inside the camera: zcame1_0x48 The sensor responds with the temperature value encoded in 12 bits.

The terminal program on my PC has macro key functionality, which enables me to send the required binary strings to the camera. E.g. to switch to stills mode, I send these four binary bytes (here in decimal); 234, 2, 1, 3 which is 0xea 0x02 0x01 0x03 when expressed in hexadecimal.

It looks like a rat's nest, but it works... 😃 z_cam_e1_uart_control_www

e1_io_pinout_www2

Cheers, Ragnar

CGFlyer85 commented 6 years ago

@RagnarJensen , that wonderful ! Is there any way we can talk about all of this, and if possible if you can help me make it work my side, off course if you need something in compensation (wink, wink) I'm okay with that's.

garciaanto commented 6 years ago

I totally forgot this post that I opened. I have it also working. In my case I couldnt make it works with eeprom but I used an small arduino instead. And to be honest I do not respond to the temperature query :)

To test it I just used a simple vb .net program to test some functions and more or less was working. Also, I upgraded the cam to the WEB latest on using the manual process (just drop the image on the root folder)

Good luck!

skadiexe commented 6 years ago

@garciaanto could you show the sketch?

garciaanto commented 6 years ago

Sure:

#include <Wire.h>

void setup() {
  Serial.begin (9600);
  Wire.begin(0x51);
  Wire.onRequest(requestEvent);
}

void loop() {
  // :DD
}

void requestEvent() {
  Wire.write(0x03);
  Serial.println (" envío un 0x3");
}
CGFlyer85 commented 6 years ago

@garciaanto do you have a wiring Shem for the Arduino ?

garciaanto commented 6 years ago

Not sure if I understand your question. If you ask regarding the connections:

CAM side Arduino side GND GND SDA SDA SCL SCL

If you want, you can also power up the arduino with the cam (CAM VCOM to Arduino Vin)

CGFlyer85 commented 6 years ago

@garciaanto, that's it. On your sketch, where do I need to put my code ? For example if I whant to focus forward or backwards ?

CGFlyer85 commented 6 years ago

Is it even possible to do this ? Because that really one thing that I need, be able to manually focus thought the I/O port...

CGFlyer85 commented 6 years ago

@garciaanto did you find a way to manually focus with it ? Don't seem to find the code to use...

garciaanto commented 6 years ago

@CGFlyer85 wait wait... My code the only thing that do is to enable the cam in uart mode. I mean, the little sketch that I wrote its only to let the cam boot on UART mode.

Once the cam is in UART mode, you can send commands to TX RX. You can find all availables command in " Z-Camera-Doc/expansion/expansion.md"

You can do that with arduino, or with vb .net or any other app.

RagnarJensen commented 6 years ago

Yes, it is possible to focus "manually" with UART commands. I put "manually" in quotes, because the camera must be in AF mode for it to work. EDIT: Later experiments show that the camera does react to focus commands when in MF mode.

I've been experimenting with some of the commands in "Z-Camera-Doc/expansion/expansion.md" and so far I've been able to

In the screenshots from my logic analyzer below, Async 0 is the camera's RX line, i.e. commands from my computer to the camera. Async 1 is the camera's TX line, responses from the camera to my computer.

If I send this, which is the GET CAMERA_CONFIG_LENS_FOCUS_POSITION command, image the camera responds with image The four bytes highlighted in yellow hold the current lens position. In the pic above it's focused at infinity. When focused at its near limit, the camera's response on the query is image Note the change in the yellow framed bytes. I have only tested with one lens (Olympus 25mm/1.8) so far, but I suspect the position values for close focus and infinity might be different for other lenses.

Finally, by sending SET CAMERA_CONFIG_LENS_FOCUS_POSITION commands, it is possible to position the focus point anywhere between the end points.

Command to set focus to near limit - focus position in the four bytes framed in yellow: image

Command to set focus to infinity: image Command to set focus somewhere in-between: image

I'm still very much in exploratory mode. I feel that the documentation on the UART commands is somewhat lacking in details... :stuck_out_tongue_winking_eye: So, I've been doing a lot of trying out things, testing and experimenting. But at least I now know the key press sequence to reset the camera to factory defaults by heart :laughing:

I'll be away for a while, but I'll try to do a little write-up and maybe some code example when I get back.

Cheers, Ragnar

MechtEngineer commented 6 years ago

@garciaanto would you mind posting some simple example Arduino code using the commands from the Github "Z-Camera-Doc/expansion/expansion.md"? For example, changing from the default video mode to stills mode?

If I can connect to the Z-CAM via I2C without having to use an EEPROM, that would be amazing!

MechtEngineer commented 6 years ago

@RagnarJensen You have made some excellent progress in the area of manually focussing the camera via UART commands. Would you mind posting your order of commands from camera startup to manual focus at infinite? Even better (and perhaps more convenient for you), some code would be excellent for this procedure.

My plan was to do something like the following:

  1. Use _CAMERA_CONFIG_FOCUSMETHOD (Command No. 22, Hex 0x16) to change the focus from Automatic Focus to Manual Focus
  2. Use _CAMERA_CONFIG_MFDRIVE (Command No. 33, Hex 0x21) to "set MF drive". I'm not sure what "set MF drive" actually means ("Set MF drive" is used as an example in the Github expansion.md file).
  3. Use _CAMERA_CONFIG_LENS_FOCUSPOSITION (Command No. 52, Hex 0x34) to change the focus to infinite. I was hopping that infinite focus would be as simple as 0xFF, but from your post above, it seems like that is not the case.
MechtEngineer commented 6 years ago

@RagnarJensen I noticed that in your focus commands, the third byte is 0x07, whereas the UART documentation says the third byte in UART SET CONFIG commands should be 0x04. Is there any reason for you changing it to 0x07?

RagnarJensen commented 6 years ago

@MechtEngineer The third byte is the length of the command or the response. E.g. in the GET CAMERA_CONFIG_LENS_FOCUS_POSITION command it is 0x02 and in its response it is 0x13.

I have no idea what the set MF drive command is supposed to do. I've only looked at it briefly, but I think I saw the focus position in the responses. And in their example, the length byte of it seems to be wrong.

RagnarJensen commented 6 years ago

I have actually never written code for an Arduino before... :flushed: This is my very first attempt ever, so go easy on me...

I have a couple of Teensy 2.0s left over from another project. I didn't write any code for them, other people did. I just integrated stuff.

The Teensy is a very close relative to the Arduino, it uses the ordinary Arduino IDE for coding stuff. So, I thought "how hard can it be?" Yes, famous last words, I know :wink: It turned out not being too hard after all. I have managed to slap together a proof-of-concept sketch that actually does some things OK.

From the comments in the code: "What this sketch can do:

The code so far is of the "ugly hack" variety. It's definitely not pretty, but it may serve as an example for how to do UART communications with an Arduino.

I have set up a repository where I will publish the results of my experiments. You can find the sketch there. RagnarJensen/Z-CAM-E1-IO

test_setup Bitscope oscilloscope/logic analyzer, breadboard, camera, batteries as focus targets and a CVBS monitor. The grey, furry things on the camera are Rycote Micro Windjammers.

-- Ragnar

RagnarJensen commented 6 years ago

I've been messing around with my Arduino code and have now pushed a new sketch to my repo. It can do everything the earlier one did, but I've added analog input.

From the comments in the code: "What this sketch can do:

focus_control_by_analog_input When I move the slider, the lens focus follows. It actually works pretty well :smiley:

The code is still ugly as sin. I'll clean it up later. Maybe... :grinning:

Cheers, Ragnar

MechtEngineer commented 6 years ago

@RagnarJensen Wow! This is absolutely magnificent! Thanks for all of your effort in posting your code and circuit. Outstanding stuff. I salute you!

RagnarJensen commented 6 years ago

Using flash with the E1. That's the reason I got interested in the I/O port, the API and UART control in the first place.

I've been mucking about with my Arduino code and I've added a resistor and a transistor to the breadboard. I can now trigger a flash from the controller. There are limitations, though. The electronic shutter's slow read-out speed and delays of varying duration in the camera make for some interesting challenges.

Head over to my repo for more info.

first_flash_pic_with_zcam_e1 This is my very first successful picture taken with the Z CAM E1, using electronic flash as illumination.

@Chenel000 Thanks for the postcard :smile:

Chenel000 commented 6 years ago

Nice you like it @ @RagnarJensen

Chenel000 commented 6 years ago

Currently I am working on building my drone where I expect to fly the Z E1 cam and use the connectors you send me, and really I miss to have time now to work on the programming side to configure and manage the camera. I expect soon to be able to join the team to work on this but first I need to finish with the flying platform. My congratulations for job you are doing.

gius19 commented 2 years ago

Hi, I found these resources on Z cam E1 looking in internet for help. I am interested in this camera for setting up a group of 4 cams to take pictures at the same time and then to stitch in pano pictures. I will use manual fisheye lenses, no need to focus. Before buying I would need to to know if this cam may comply some requisites. 1) I have a sony camera and for this purpose I use the function "enable picture without lens": is it possible to do the same with Zcam E1? 2) Is it possible to set "aperture priority" and set a maximum limit in exposure time (e.g. not more than 1/1000s)? 3) I would like to connect all the cams (via usb or other ports, connecting cables) to take a picture simultaneously. Is there a port for wired shutter release?

Thank you in advance for any hints and help.

Giuseppe