Main Site Documentation

L1 camera taking 1 picture and no more


#1

Hi

I have adapted the C# program from GHI to take a single picture on a button press. It works once, then when I press the button a second time nothing happens at all!

This is the code I have adapted:

Imports System
Imports System.Collections
Imports System.Threading
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Presentation
Imports Microsoft.SPOT.Presentation.Controls
Imports Microsoft.SPOT.Presentation.Media
Imports Microsoft.SPOT.Touch

Imports Gadgeteer.Networking
Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics

Namespace serial_camera
    Partial Public Class Program
        Dim LCD As Bitmap
        Dim cnt As Integer
        Dim font As Font
        ' This is run when the mainboard is powered up or reset. 
        Public Sub ProgramStarted()
            font = Resources.GetFont(Resources.FontResources.NinaB)
            '  serCam.SetImageSize(Gadgeteer.Modules.GHIElectronics.SerCam.Camera_Resolution.SIZE_QQVGA)
            oledDisplay.SimpleGraphics.AutoRedraw = True
           
            Debug.Print("Program Started")
            oledDisplay.SimpleGraphics.DisplayText("test", font, GT.Color.Blue, 30, 50)
            Thread.Sleep(2000)
            oledDisplay.SimpleGraphics.Clear()
            LCD = New Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight)
            cnt = 0

        End Sub
        Sub VideoStreaming()
            serCam.StartStreaming()
            LCD.Clear()
            While (True)
                Thread.Sleep(30)
                If (serCam.isNewImageReady) Then
                    serCam.DrawImage(LCD, 0, 0, SystemMetrics.ScreenWidth, SystemMetrics.ScreenWidth)
                    oledDisplay.SimpleGraphics.DisplayImage(LCD, 0, 0)
                    serCam.StopStreaming()

                    'cnt = cnt + 1
                    ' If cnt > 1 Then
                    'serCam.StopStreaming()
                    '  serCam.StartStreaming()
                    '  oledDisplay.SimpleGraphics.Clear()
                    ' End If
                End If
            End While
        End Sub

        Private Sub button_ButtonPressed(sender As Button, state As Button.ButtonState) Handles button.ButtonPressed
            serCam.isNewImageReady = True
            Call VideoStreaming()

        End Sub

    End Class
End Namespace

As I say it works fine once. The “test” display comes up and goes, the screen waits for the button, it then takes and displays a single frame (from the camera) but when the button is pressed again nothing happens.

Thanks

(PS I am using the L1 serial camera and a Fez Hydra on VB2012)


#2

Your not exiting your whole true loop

WHILE (iPhone will not stop “autocorrecting” that from syntax)


#3

Thanks Skewworks I will have a go at that. Thanks for the fast response.


#4

Hi Skewworks that has worked great thanks. One final question when I take the first image it displays fine, then when I press it again the image on the OLED is all stripy and messy - please see attached image. Is it the program or is my OLED display hardware playing up?

Thanks

Linkin


#5

The driver is not very smart and I believe your passing an image that is not exactly 128x128 which will mess up following writes. To correct reset OLED between flushes or size image perfectly.


#6

I have been using oled display.simplegraphics.clear() and it doesn’t seem to be completely flushing/clearing/wiping (whatever word you want to use!), it appears to overlay next graphic on the top or just make the screen all stripy as in the attached picture. Is there a way to actually restart the screen or do a proper clear?


#7

Maybe not the display is the problem.
I think taking a streming picture is the problem.
how to syncronice “beginning” of picture in the data stream.

have a look at your code


                    'cnt = cnt + 1
                    ' If cnt > 1 Then
                    'serCam.StopStreaming()
                    '  serCam.StartStreaming()
                    '  oledDisplay.SimpleGraphics.Clear()
                    ' End If

maby there is the answer…


#8

Hi Daniel

As I said I adapted the code from the C# post on the GHI forum, The C# lines were (if I remember right)

 cnt++
if cnt 10 % ==0

The closest translation I could find was the

cnt = cnt + 1
                    If cnt > 1 Then

Have I converted that correctly or not?

Thanks

Linkin


#9

Hi, the C# line ‘if (cnt % 10 ==0)’ should translate into VB as ‘If cnt mod 10 = 0 Then’.


#10

Hi no this still isn’t working. This is my code:

Imports System
Imports System.Collections
Imports System.Threading
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Presentation
Imports Microsoft.SPOT.Presentation.Controls
Imports Microsoft.SPOT.Presentation.Media
Imports Microsoft.SPOT.Touch

Imports Gadgeteer.Networking
Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics

Namespace serial_camera
    Partial Public Class Program
        Dim LCD As Bitmap
        Dim cnt As Integer
        Dim font As Font
        
        ' This is run when the mainboard is powered up or reset. 
        Public Sub ProgramStarted()
            font = Resources.GetFont(Resources.FontResources.NinaB)

            Debug.Print("Program Started")
            oledDisplay.SimpleGraphics.DisplayText("test", font, GT.Color.Blue, 30, 50)
            Thread.Sleep(2000)
            oledDisplay.SimpleGraphics.Clear()
            LCD = New Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight)
            cnt = 0


        End Sub

        Sub VideoStreaming()
            serCam.StartStreaming()
            LCD.Clear()
            While (True)
                Thread.Sleep(100)
                If (serCam.isNewImageReady) Then
                    serCam.DrawImage(LCD, 0, 0, SystemMetrics.ScreenWidth, SystemMetrics.ScreenWidth)
                    oledDisplay.SimpleGraphics.DisplayImage(LCD, 0, 0)
                    serCam.StopStreaming()
                    cnt = cnt + 1
                    If cnt Mod 10 = 0 Then
                        serCam.StopStreaming()
                        serCam.StartStreaming()
                        oledDisplay.SimpleGraphics.Clear()
                              End If                       
                    Exit While
                End If
            End While
        End Sub
        

        Private Sub button_ButtonPressed(sender As Button, state As Button.ButtonState) Handles button.ButtonPressed
            oledDisplay.SimpleGraphics.Clear()
            Thread.Sleep(1000)
            Call VideoStreaming()
        End Sub

    End Class
End Namespace

And this is the code from http://www.ghielectronics.com/docs/176/serial-camera-module:

1.
using System;
using System.Collections;
System.Threading;.
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;.
using Microsoft.SPOT.Presentation.Controls.
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;.
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace EMX_TestSerCam_4250

    public partial class Program

         void ProgramStarted()

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.

            new Thread(VideoStreamming).Start();
            Debug.Print("Program Started");

        static Bitmap LCD = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
.
        int cnt = 0;
.
       void VideoStreamming()
        {
            serCam.StartStreaming();
            LCD.Clear();
            while (true)
            {
                Thread.Sleep(100);
                if (serCam.isNewImageReady)
                {
                       
                   serCam.DrawImage(LCD, 0, 0, SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
                    display_T35.SimpleGraphics.DisplayImage(LCD, 0, 0);
                    cnt++;
                    if (cnt % 10 == 0)
                        serCam.StopStreaming();
                        serCam.StartStreaming();
                        display_T35.SimpleGraphics.Clear();
                    } 
                }     
            }
        }
    }
}


Again it takes the first image after rebooting perfectly, fits it to the OLED perfectly, then when you press the button again the screen clears and this time the image is like the attached image. I can tell the new image is just that new because if you move the camera between shots you can make out that it is a new image not just a mixture of both images.

But like I say if you use the reset button on the board it then will restart and take the first image no problem…


#11

I still can’t get it to sync properly after the first image. Does anyone have any ideas? I have tried changing the thread timings and the call but I cant seem to get it to do more than take the first image.


#12

Take out the screen aspects, write to a file. Then see if the two captures are still the same.

Then, I’d restructure the While(true) and not rely on the Exit While.

Then, I’d ask, why do you stop streaming then start streaming again; the second time through that routine, streaming in theory would be running, so is that related to your error?


#13

Default it will be 240x320, in the driver, there is a function to resize to 128x128, did you try it?


#14

Hi Dat

I couldn’t see how to force the resize on to the image… Is there a line I just need to add in?


#15

You can copy it to a new image of the right dimensions. Or as I suggested earlier reset the OLED between draws.