Top Banner
Getting started with Microsoft .NET Gadgeteer Comberton Village College Gadgeteer Club
48

Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Dec 25, 2015

Download

Documents

Cornelia Harper
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Getting started withMicrosoft .NET Gadgeteer

Comberton Village CollegeGadgeteer Club

Page 2: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

The .NET Gadgeteer HardwareAt the heart of every Gadgeteer project is a mainboard. A mainboard is made up of a programmable processor, and a number of sockets that Gadgeteer modules can plug into.

Page 3: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Can you find the……

Touchscreen Display

Page 4: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Camera

Can you find the……

Page 5: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Multicolor LED

Can you find the……

Page 6: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Button

Can you find the……Can you find the……

Page 7: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Potentiometer

Can you find the……

Page 8: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

USB Host

Can you find the……

Page 9: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Ethernet

Can you find the……

Page 10: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

SD Card

Can you find the……

Page 11: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

USB Power Supply+ Programming Interface

Can you find the……

Page 12: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

There are also…• Some connector cables (same both ends)• Some extender cards• A black USB wire to power the power card

Page 13: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

A Closer Look at the Mainboard

Power LED Debug LED

Reset Button

Page 14: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Mainboard Socket Numbers

Page 15: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Mainboard Socket Types (Letters)

Page 16: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Socket Type Compatibility Labels

“X or Y”

Page 17: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Match socket type letters when connecting modules to the mainboard

Page 18: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.
Page 19: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

• If a module is connected to the wrong socket type it won’t work (but it won’t damage anything, either)

• Red modules supply power to the mainboard. Only one red module should ever be connected to the mainboard at any time. (We only have one type of power card at the moment)

• When connecting modules, always make sure that the mainboard is not powered on, and that it is disconnected from the PC.

Page 20: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Constructing a Digital CameraWhat components will we need to make a camera like this one?

Page 21: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

We need….• Main board• Power board• Screen• Button• Camera module• We could also add an SD card….later….

Page 22: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Let’s connect it together like this…

Page 23: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Creating a New Gadgeteer Project

Open Microsoft Visual C# 2010 Express, and select New Project… from the Start Page. (Alternatively, select File > New Project).

Page 24: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Select Gadgeteer from the list of Installed Templates, then select .NET Gadgeteer Application. You can give your project a name, then select OK.

Page 25: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Designer Tab(Program.gadgeteer)

Solution Explorer(Project Files)

Page 26: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Code Tab(Program.cs)

Page 27: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Designer Tab(Program.gadgeteer)

Toolbox

Page 28: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.
Page 29: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

You can rename button. For example, rename it to myButton.

Page 30: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Click and drag to connect the button to a compatible socket.

Click on the button’s socket. Compatiblesockets on the mainboard are highlighted in green.

Page 31: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Add USBClientDP module from the toolbox, and connect it to socket 1.

The USBClientDP module is both a power supply and a USB programming interface.

Page 32: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Now make the image in C# look like the Gadgeteer you have made…

Make sure that you use the right sockets.

The diagram in C# must be the same as your actual gadget.

Page 33: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Now we will write the code to make it work

There are different parts to code in C# (and other languages).We will use terms like:• Properties• Events• MethodsDon’t worry about them too much at the moment….let’s just get something that works!

Page 34: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

If it tells you text template may damage your computer…..

Make sure that you click ‘OK’

Page 35: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

When the button is pressed…

Inside the ProgramStarted() method, type module name followed by a period, then select event using the arrow Enter keys.

We want to say that once the program has started, if the button is pressed (an event), something happens (a method)

Page 36: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Type +=, followed by the Tab key twice.

Page 37: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Replace the line throw new NotImplementedException(); with your own code.

Replace it with:

Page 38: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

When the camera receives an image…We want to say that once the program is started, if the camera receives an image (the event), something happens (the method)

Inside the ProgramStarted() method, type module name followed by a period, then select event using the arrow Enter keys (like we did for the button.

You will have two lines inside the ProgramStarted() method now…..let’s finish off the camera method…

Page 39: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

When the camera has captured a picture, use the display’s SimpleGraphics to display the image.

Page 40: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

The DisplayImage method takes three parameters: a Picture object, an X coordinate and a Y coordinate.

The PicturedCaptured event returns a Picture object, called picture, which can be directly passed to the DisplayImage method as the first parameter.

The coordinate 0, 0 (passed as the second and third parameters) refers top-left corner of the display.

Page 41: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

This is what the completed program should look like (comments and spare lines removed).

void ProgramStarted() { camera.PictureCaptured += new Camera.PictureCapturedEventHandler(camera_PictureCaptured); myButton.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed); Debug.Print("Program Started"); } void button_ButtonPressed(Button sender, Button.ButtonState state) { camera.TakePicture(); } void camera_PictureCaptured(Camera sender, GT.Picture picture) { display.SimpleGraphics.DisplayImage(picture, 0, 0); }

Page 42: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

t

Connect modules to mainboard, and connect to PC via USB.

To PC

Page 43: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Now let’s run our program…Save your project and the program file to your own area.Press ‘run’ on the toolbar

Page 44: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

What happens?Be patient….In the output window you will see messages about debugging and rebooting.The program is being transferred to the main board, which will then reboot itself and run the program.You will know it has done this (and is ready) when it says “Program Started” in the window.ONLY THEN CAN YOU TEST YOUR CAMERA.

Page 45: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

If you see the following message in the output window, stop debugging (Shift+F5) and try again (F5):

Updating display configuration. DEVICE WILL NOW REBOOT. Visual Studio might lose connection, and debugging might need to be manually restarted.

If the output window is stuck displaying the following message, press the reset button on the mainboard:

Rebooting...

Page 46: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

When the Program is running…1. Press the button – an image should be

displayed on the screen.2. You may wish to hold the camera steady and

re-focus a little at a time until the image improves

Page 47: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

You can also use SimpleGraphics to perform basic drawing operations.

For example, use it to overlay a rectangle on top of the picture.

Page 48: Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.

Use the prompts and drop-down lists to discover and select the appropriate parameters.