Notifications
Clear all

Need Help with GPIO display and Camera Preview

26 Posts
3 Users
0 Likes
1,801 Views
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  
Posted by: @frogandtoad

A quick search led me to the following, which may be of interest to you:

DIY WiFi Raspberry Pi Touchscreen Camera

I see from that article that there are a LOT of specific little quirks that must be taken into consideration.   And apparently the specific display I'm using simply doesn't qualify for the restricted parameters they require.  So based on that article (i.e. any attempt to duplicate what they are doing exactly) would require that you obtain all the parts they are using pretty much verbatim.

Too bad I didn't see that article first.

I can make my current system work using jpegs as the preview.   The live preview is the only part of the system I haven't been able to conquer.   Other than that, it's already up and running taking videos.  If I was building a dash cam where a preview isn't required I'd be done already.

I have one more thing I'm going to try.  It's a long shot, but it might work.  It's just another attempt using the VNC method that @byron suggested.   Last night while sleeping I thought of some things that might work.  But then again they might not.  So I'm back to experimenting some more.

If this doesn't work I'll just move on with using jpegs to preview and focus the shot.  That will be a bit cumbersome and not as nice as a live preview.  But at least it will get me by for now.  For focus I can also adjust the focus for a predefined distance.   Then I can just always set the camera up precisely that distance from the target.  That's a slight limitation, but it would save having to refocus the camera with every new video.  Then all I would need to worry about is getting the shot in the frame correctly.  Jpeg previews could work for that fairly well.  The camera will be on a tripod so once the shot is set up I could take several videos using that setup.  I'll be filming various machining operations on a lathe and milling machine.  So there's a lot of meticulous setup for the machining operations anyway.  Having to set up the camera after all that won't be all that bad since the camera won't need to be dialed into within a thousands of an inch.  I can set the camera up with a simple ruler.  That will seem easy after having set up the part in the machine with precision dial indicators.

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

I've finally achieved some level of success!

 

Right now it's a bit complicated to explain.  But here's what I did.

1. Command the pi zero to revert to using the HDMI display.

This results in having no display at all on the pi zero because I don't have an HDMI monitor connected.

2. Then I connect to the pi using the VNC viewer.  I can see and interact with the pi desktop and command line from there.

3. I then set the VNC server options on the pi zero to Enable Direct Capture Mode

4. Then I have to reset the pi zero to go back to using the GPIO display.

This requires a reboot.

2. Now when I launch the VNC viewer all I see is the last past of the boot log.

This is a totally static page that I cannot do anything with.  it's apparently the last thing that was sent to the HDIM monitor before reverting back to the GPIO display during reboot.

3. I had been here before and thought this was hopeless at this point since I was unable to interface with the Pi Zero desktop using the VNC viewer.

~~~~~

But then I realized the following:

4. I could still connect to the Raspberry Pi using Remote Desktop because it wasn't set to enable direct capture mode.   So it sees what's being sent to the GPIO display (i.e. the pi zero desktop)

5. A bit of a bummer:  Every time I switch the pi zero from GPIO to HDMI it automatically also disables the camera.  Why it does that I don't know, but this required that I re-enable the camera again and go through yet another reboot.

~~~~~

Finally, after having done all of the above I was able to use the Remote Desktop to launch my video camera program and sure enough the video preview did indeed show up in the VNC viewer!

This might sound like a bit of nightmare, and it would be if I had to do all of this every time.  However, once this configuration is set up it should remain this way.

~~~~~

The good news:   I really don't need the Remote Desktop to run the camera program.  I can do that using the GPIO touchscreen.   So the Remote Desktop isn't required for the final version of this project.

~~~~~

The NEXT CHALLENGE:

I'm currently running the VNC viewer on a Windows machine.  However, in theory I can run the VNC viewer right on the pi zero.  A Raspbian version of VNC viewer is available.   So I should be able to have the pi zero serve itself its own HDMI image via VNC server/viewer on the same machine.

If that works, and it should, then I should be home free having everything self-contained on the pi zero.

The only slight drawback now is that the VNC server/viewer appears to require that I'm within reach of a WiFi router.   Since I'll be using this out in the shop where there is no WiFi router, I'm not sure if it will continue to work out there.

~~~~~

Any WiFi experts out there?  Is there a way that I can have the Pi Zero connect to itself via its own WiFi?

In other words, can I have the VNC viewer recognize the pi Zero directly without having to go through a router.   Can it be on the same machine that it is being asked to view?

~~~~~

The fun thing about these projects is that I'm constantly learning new tricks of what can and cannot be done. 😎 

Looks like I might be close to being home free on this project.  Getting the VNC server/viewer to work on a single machine without a router is the last challenge.  If I can beat that one, I'm done!

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  

More success:

I've installed VNC viewer on the Raspberry pi.  So now the pi is capable of viewing itself. 🤣 

That may seem ridiculous, but this is what is required to view the HDMI output on the GPIO display.

The video preview is very jerky and slow.  No doubt due to the limitations of a Pi Zero.   None the less, it's still far better than trying to use individual jpegs.  This video is updating in far less than a second per frame.  I couldn't get that fast of an update with jpegs.   So I guess this is as "live" as the preview is going to get.

That's ok.  I only need to use the preview to focus and center the frame of view.  I'll turn it off when I actually record the video.  I don't need to see the video during recording.

So I'm pretty close to being home free.   The only question at this point has to do with the WiFi connection.  I'm guessing that the VNC server is putting out the image to my home WiFi router, and the VNC viewer is then obtaining the image via WiFi from the router.

If I could by-pass the router to where the pi zero is basically talking to itself via it's own WiFi that would free me up from being dependent on being within range of my WiFi router.

Not sure if that's possible?  I'm not a WiFi expert. Far from it.  I'm lucky to keep things working using a router. 😮 

In any case, I'm making progress here.

Thanks to @byron for pointing me to the VNC server/viewer.  That does seem to be the tool that has made it possible thus far.   It's a little tricky to set up for exactly how I needed it, but it does work in the end.   The slow refresh rate of the preview video must be due to the pi zero.  I didn't notice any lag when I viewed this on the Windows machine.  But I can deal with this slow frame rate.  All I need is to focus and center things in the field of view.  As long as I can do that, I'm all set.

 

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robo-pi

Posted by: @robo-pi

I see from that article that there are a LOT of specific little quirks that must be taken into consideration.   And apparently the specific display I'm using simply doesn't qualify for the restricted parameters they require.  So based on that article (i.e. any attempt to duplicate what they are doing exactly) would require that you obtain all the parts they are using pretty much verbatim.

Too bad I didn't see that article first.

OK, fair enough... was worth a try I guess.

Out of curiosity, what were the specific quirks you mentioned that required consideration? - If we know what they are, we might come across new information that may help.

And also, what type of 3.5" GPIO touchscreen display do you have exactly? ...resistive?, capacitive?

Posted by: @robo-pi

I didn't notice any lag when I viewed this on the Windows machine.  But I can deal with this slow frame rate.  All I need is to focus and center things in the field of view.  As long as I can do that, I'm all set.

No surprising - It's widely acknowledged that Windows RDP is far better in terms of display resolution and speed over VNC (you might want to try that as well), but if VNC does the job for you, that's all that matters.  By the way, did you test RDP with the switches I provided, and, did it allow you to see the correct session?


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  
Posted by: @frogandtoad

Out of curiosity, what were the specific quirks you mentioned that required consideration? - If we know what they are, we might come across new information that may help.

Well, I'm not sure if the specs they are using would apply to my application since I'm not trying to duplicate their design.

One spec they give is that the display must be 320 x 240 and no higher.  This rules out any 3.5" display according to them.   Since I'm using a 3.5" display I'm already living in a different universe from them.  My display has a resolution of 480 x 320.  So I'm already out of their ball park.  My display is not going to work with their design.  But their design is clearly not the only way that things can be done.

They demand that the touchscreen must have a resistive touch, not capacitive.   I don't even know what kind of touch technology my screen uses.  All that matters to me is that it works to launch and control my programs.  Why they require a specific technology is beyond me.   And like I say, I don't even know which technology my touchscreen uses.

Here's where I bought mine on eBay:

3.5" LCD Touchscreen

Posted by: @frogandtoad

And also, what type of 3.5" GPIO touchscreen display do you have exactly? ...resistive?, capacitive?

It doesn't say whether it's resistive or capacitive.   Or at least I couldn't find those specs.

I don't see what any of that would have to do with viewing a camera preview anyway. 

I'm not having any problems with the touchscreen.

Posted by: @frogandtoad

By the way, did you test RDP with the switches I provided, and, did it allow you to see the correct session?

No I didn't because I don't currently have a need to modify RDP right now.  I won't be using RDP in the finished product.  I would like to learn about those switches though.  But I don't have time right now to go off on tangents that aren't directly applicable to my immediate goal.

~~~~

Right now I'm having yet another problem with the VNC VIEWER (not the VNC server).

When I run the VNC viewer on the pi zero with the touch screen I can't see it because it apparently opens as a humongous window that I cannot move around in.  There are no slider bars on the sides of the screen and no way to move around in the window.  Because of this, I have not yet been able to run the VNC viewer directly from the pi zero touchscreen.

I'll probably need to set some sort of display properties of the VNC viewer software to show up on a 480 x 320 screen.  But thus far I haven't been able to find a way to do this.   I've been searching for how to do this on the web, but all they show me are property menus that I can't even get to until I first get the thing to show up properly.

I'm hoping to find a  VNC viewer command prompt where I might be able to launch it from there with options for a 480 x 320 screen.

~~~~

This is my life story!  I'm always wanting to do one thing (in this case make a little close-up camera), but instead of focusing on that task I find myself spending my life trying to figure out how to get software tools like VNC viewer to behave properly. 😮 

I've gotten past the part of getting it do display the preview.  Now I just need to get it to behave well on a 480 x 320 screen. 😊 

Maybe it won't work on a 480 x 320 screen?  See, I don't even know if it can do this, much less how to make it do it.

 

 

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robo-pi

Posted by: @robo-pi

One spec they give is that the display must be 320 x 240 and no higher.  This rules out any 3.5" display according to them.   Since I'm using a 3.5" display I'm already living in a different universe from them.  My display has a resolution of 480 x 320.  So I'm already out of their ball park. 

OK, that appears to be a major issue then, thus the solution is dead.

Posted by: @robo-pi

They demand that the touchscreen must have a resistive touch, not capacitive. 

I had come across some other articles which also specified the same requirement, so the reason for my asking.

Posted by: @frogandtoad

By the way, did you test RDP with the switches I provided, and, did it allow you to see the correct session?

No I didn't because I don't currently have a need to modify RDP right now.  I won't be using RDP in the finished product.  I would like to learn about those switches though.  But I don't have time right now to go off on tangents that aren't directly applicable to my immediate goal.

Fair enough, but note that you wouldn't be modifying anything by using those switches on the command line... do let us know how it works when you actually do get the time to test it out.

Posted by: @robo-pi

Right now I'm having yet another problem with the VNC VIEWER (not the VNC server).

When I run the VNC viewer on the pi zero with the touch screen I can't see it because it apparently opens as a humongous window that I cannot move around in.  There are no slider bars on the sides of the screen and no way to move around in the window.  Because of this, I have not yet been able to run the VNC viewer directly from the pi zero touchscreen.

I'll probably need to set some sort of display properties of the VNC viewer software to show up on a 480 x 320 screen.  But thus far I haven't been able to find a way to do this.   I've been searching for how to do this on the web, but all they show me are property menus that I can't even get to until I first get the thing to show up properly.

I'm hoping to find a  VNC viewer command prompt where I might be able to launch it from there with options for a 480 x 320 screen.

This may or may not work for you, but I have experienced these issues with VNC before.  If you click somewhere in the session window to FOCUS it, you should be able to use the arrow keys or page up, page down keys enough to navigate to the menu's, etc... worth a try.

Posted by: @robo-pi

This is my life story!  I'm always wanting to do one thing (in this case make a little close-up camera), but instead of focusing on that task I find myself spending my life trying to figure out how to get software tools like VNC viewer to behave properly.  

You, me, and many others before us!

At the end of the day, learning is frustrating, but also fun!

When you get to the point of confidently smacking the living daylights out of a little freaking golf ball that's been haunting you your whole life, then you have succeeded nothing, but gained an appreciation of knowledge and skill to move forward to succeed in your domain 😉


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @robo-pi

instead of focusing on that task I find myself spending my life trying to figure out how to get software tools like VNC viewer to behave properly

Yes, there go I. 😎  and worse having figured out stuff a while back finding oneself doing it all again on half remembered stuff. 

So here a few half remembered stuff that probably wont be of much use, but just in case:

1. you should be able to use 'localhost' when using the vnc client on the same box as the server and I don't think localhost goes to the router.

2. as the VNC client seems to default to the resolution of the htmi screen the supposedly is attached to the pi you could try to set the screen resolution for the pi in config.txt.

3. you can try to set the screen resolution in vnc when initiating the server - e.g. vncserver -randr=1920x1080

4. I remember a few years back whilst on a contract in Sydney and spending many months in a hotel I got a small mini wifi router to extend the single ethernet connection coming into the room to being a mini travelling wifi hotspot.  If localhost does not work then maybe one of these small gizmos are still available.

Ah yes, memories...


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  
Posted by: @byron

1. you should be able to use 'localhost' when using the vnc client on the same box as the server and I don't think localhost goes to the router.

This is something worth learning about because I'm building two of these pi zero cameras.  So getting them up and running independent of a WiFi access point would be worth it.   I might want to use them where there is no WiFi access point (like in my shop).  😎 

Posted by: @byron

2. as the VNC client seems to default to the resolution of the htmi screen the supposedly is attached to the pi you could try to set the screen resolution for the pi in config.txt.

Learning how to properly set up my screen resolution is something I need to do.  There  is a calibration program that came with it and it worked when I first set it up, but now it quit working.   It's my understanding that the calibration program just modifies a calibration config file.

Here's my calibration config file:

ection "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "3936 227 268 3880"
Option "SwapAxes" "1"
EndSection

Clearly the screen can be calibrated by typing the correct numbers into this file.   The problem is I don't know what numbers to type in.  I'm not understanding the coordinate system they are using.

Obviously the following line needs to be modified:

Option "Calibration" "3936 227 268 3880"

But what numbers should I use?  The current numbers aren't making a lot of sense to me.  I've been trying to find information on the web concerning what numbers I need to type in here, but thus far I haven't been able to find a sane explanation. 🤣 

I don't understand why they don't just have something like "480 x 320" or "1920 x 1080"?

I don't know what "3936 227 268 3880" means.

I can probably resolve this screen resolution problem once I figure out what numbers I need to type into this config file.

By the way this config file is located at:

/etc/X11/xorg.conf.d/99-calibration.conf

But this directory and specific config file was probably created when I installed the GPIO display software?  So it probably won't exist on a standard Raspbian system.  I don't even know if that's true.

Posted by: @byron

3. you can try to set the screen resolution in vnc when initiating the server - e.g. vncserver -randr=1920x1080

The problem is that I'm having screen resolution problems upon launching the VNC viewer BEFORE even connecting to a computer.   So this particular resolution problem isn't likely to be associated with the vncserver. The vncviewer isn't connect to the server yet.  I can't even launch the vncviewer on the pi zero screen to connect to the vncserver.

So this probably needs to be done in my calibration.conf file.  I'll have to learn what numbers I need to use in that config file.

Why can't these people make things easy?

What the heck does ""3936 227 268 3880" mean?  And what numbers do I need to type in to change the resolution to 1920 x 1080, or 480 x 320?   Also could I use 1280 x 720?  I don't even know what my options are or which would be best for my purposes.

You need to have a Ph.D. in software/hardware design just to get anything to work anymore.  It's ridiculous.  I thought things are supposed to be getting easier to use, not harder! 🤣 

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 

@robo-pi

I dont think setting the screen resolution of your didy screen is the same as setting the hdmi resolution, and it appears that the hdmi setting that the vnc client will use. I may be wrong.

And I realised that my rpi4 that I run as a control hub for a database server, mqtt broker, and the like, has a vnc client installed as part of the installation (as well as a server).  So I fired up the client and gave it the ip address of 'localhost'.  I dont know what I did as the first try had the vnc client spawning yet another local vnc window in the last vnc window and so on and ever decreasing windows.   Anyway after a reboot I tried it again and this time just the one vnc client window happily working with the pi's vnc server.


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
Topic starter  
Posted by: @byron

Anyway after a reboot I tried it again and this time just the one vnc client window happily working with the pi's vnc server.

Is that just a direct connection then?   No WiFi at all?   Could this be done on a regular Pi Zero that doesn't have WiFi?

DroneBot Workshop Robotics Engineer
James


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @robo-pi

No WiFi at all?

My connection to the pi was through a vnc client on a mac and the pi's wifi was on but I think the localhost does not go out to a router.   I just googled 'does localhost go to a router' and the answer was 'no' so I have full expectation that the link from the pi's vnc client to the pi's vnc server would work without a router.  And I cant stop the router right now as my wife is watching an Amazon prime movie streamed over the internet to verify my high hopes 🤨.   But would localhost work where an ethernet is not even being initiated on a pi? I don't know the answer to that.


   
ReplyQuote
Page 2 / 2