Stove Assistant - Unboxing

 

Last week I received a parcel from Newark element14. I opened it and found a very nice Raspberry Pi bag in it:

 

element 14 parcel with Raspberry Pi bag

Fortunately the rest of the Challenger Kit was also in it:

The Challenger Kit

So everything is there to start the challenge.

Setting up the system

 

Installation of the operating system

 

To start the development I first had to set up the system. So I took the Raspberry Pi 3, the Raspberry Pi camera, the power supply and the SD card with the NOOBS image and plugged it all together. I connected a USB keyboard, a USB mouse and a HDMI monitor and powered it up. The NOOBS system boots and asks which operating system to install. I decided to use Raspbian since it is based on debian and gives you the most freedom to install tools and make programs on your own. Furthermore there is a vivid community around who can help you with almost any problem. The raspbian is installed with a graphic user desktop. Maybe I wont need the desktop in the project, but it doesn't hurt at this time.

 

installation of raspbian

 

Configuration and additional tools

 

The raspbian system starts fully running but you may want to configure the system to your own needs or install additional tools. I love to have ssh running on the machine so that I can lie with my notebook on my couch and let the Raspberry Pi do some programming stuff in the workroom. ssh can be enabled with the raspi-config tool. If you log into your Raspbeery Pi with the '-X' option you enable the X11 forwarding. Then you have the graphic output of the programs on your Raspberry Pi on your local machine. The login works with this command:

ssh -X pi@ip_address_of_raspberry_pi

 

Additionally you have to enable the Raspberry Pi camera in raspi-config. You can test the camera with the following command:

raspistill -o test.jpg

 

This should display the output of the camera for 5 seconds on the screen and then save it to the file test.jpg. Unfortunately this doesn't work with X11 forwarding so you only see the output on the local screen of the Raspberry Pi. But I will fix this in the next chapter with OpenCV.

 

I also installed vim because I like this editor and I will do much of the programming with it. But working with the original vi is to hard for me!

 

OpenCV

OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real-time computer vision. I will use it to process the data (images) of the Raspberry Pi camera. OpenCV is written in C++ and I will write my program in C++ so this fits and I wont need any library wrapper.

First you need to install the OpenCV library:

sudo apt-get install libopencv-dev

This will install all the required packages and will take a little time.

 

OpenCV uses the Video4Linux API to capture data from the camera. Usually this is not enabled on the Raspberry Pi. So you first have to load the corresponding kernel module:

sudo modprobe bcm2835-v4l2

 

Then I will make the first demo program which will only open the camera and display the output on the screen. To simplify the compiling process I will use a makefile. Here is the content:

CXXFLAGS = -O2 -g -Wall -Wno-unused-result `pkg-config opencv --cflags `
OBJS = main.o 
LIBS = `pkg-config opencv --libs`
TARGET = main
$(TARGET):$(OBJS)
            $(CXX) -o $(TARGET) $(OBJS) $(LIBS)
all:$(TARGET)
    clean:
        rm -f $(OBJS) $(TARGET)

 

And here is the source code of the program:

#include 
#include 
#include 

int main(void)
{
    int end=1;  // variable to end program
    printf("Pi Chef Stove Assistant Demo\n");  // print start message

    cv::Mat inputImage(1024,1280,CV_8UC3);  // create opencv mat
    cv::VideoCapture cap;  // create camera input
    cap.open(0);  // open camera
    while(end==1)  // check end variable
    {
        cap >> inputImage;  // copy camera input to opencv mat
        cv::imshow("camera",inputImage);  // display mat on screen
        char key = cv::waitKey(20);  // check keys for input
        if(key=='e') end=0;  // end if e was pressed
    }
    printf("ended regularly!\n");  // print end message
    return 0;
}

 

Luckily this also works with X11 forwarding so that I can stay on my couch.

Here is the first screenshot of the output (sorry for the bad quality but it was late with dimed lighting ;-) ):

demo output of OpenCV

 

 

What's next?

I hope that this week the grid-eye sensor arrives and I will connect it to the Raspberry Pi and read out the sensor values.