Showing posts with label USB. Show all posts
Showing posts with label USB. Show all posts

Sunday, 21 August 2022

Booting using a USB



Modern computers disable booting from USB or optical drives to prevent inadvertent booting from media left in the machine.

In theory this can be switched back on by restarting the machine and hitting F2/F10 repeatedly to get into the Boot Menu.

Except Windows has an interesting trick up its electronic sleeves to make your life difficult, Fast Start.

This makes getting to the boot menu impossible (it should make the machines start faster – but only for Windows values of faster).

However, the Fast Start can be turned off.

Either search for Power Options in the task bar or Start Settings and Power Management.

Select Choose what the power buttons do.

Under the Shutdown settings section, uncheck the box next to Turn on fast Startup (recommended).

Restart the machine and hit the F2/F10 key to get to the boot menu.

There is often a Boot order option, ensure that you have the USB device before the hard drive.

Once this is set, you may think you do not have to worry about this ever again. Microsoft has other ideas – if you boot to Windows and do an update, it will switch the Fast Startup back on again and once again you will not be able to boot from USB. Just follow the instructions again.


Sunday, 5 July 2020

Reading USB (Serial) data

Most microcontrollers have an option to output data over the USB link.

It is helpful during development to be able to read state information and other values that allow the developer to see what is happening.

The first thing is to identify which USB port is in use.
            foreach (string port in ports)
            {
                Console.WriteLine(port);
            }
For my set up, COM5 was the one in use.
using (var sp = new System.IO.Ports.SerialPort("COM5", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One))
            {
                Console.WriteLine("Reading serial port");
                sp.Open();
                while (true)
                {
                    var readData = sp.ReadLine();
                    Console.WriteLine($"[{readData}]");
                }
            }
This will display on the console anything output from the device.





Wednesday, 15 May 2019

USB Webcam using a Raspberry Pi and Python - test

Introduction

USB webcams are very cheap, and in many cases you may already own one. Though the Official Raspberry Pi Camera is often far superior (many "High Resolution" webcams are 'Nineties era VGA resolution - 640x480), the fact that webcams are cheap and cased can make them very useful for some projects.

This posting covers the simplest of Python programs to take a photograph using the OpenCV library.

Installation

Install OpenCV

sudo apt-get install python-opencv libopencv-dev

You might find it is already installed.

Install Python bindings

Remember that pip probably installs for Python 2.x, so you will need to use pip3.

sudo pip3 install opencv-python

Please note that if you forget the sudo, you do not get an error, but it also does not work (you get an error "ImportError: No module named 'cv2'").

Taking a photograph

The following Python code takes a photograph and saves it to a file in the (pi) user's home directory.

The program takes a number of frames to allow the camera and its software to determine the best settings for exposure etc.

# Test USB web cam with OpenCV

# Imports
import cv2

# Set camera to be the default webcam
camera_port=0

# Set warm up number of frames
skip_frames=7

# Destination file
file="/home/pi/image.jpg"

# Set up camera properties
camera=cv2.VideoCapture(camera_port)
camera.set(cv2.CAP_PROP_FRAME_WIDTH,640) 
camera.set(cv2.CAP_PROP_FRAME_HEIGHT,480)

# Function to get image
def get_image():
    retval,im=camera.read()
    return im

# Test USB web cam
print("Starting photograph")

# Skip frames to allow camera to settle down
for skipping in range(skip_frames):
    temp=get_image()
print("Taking photograph")

camera_capture=get_image()

# Write image to file
cv2.imwrite(file,camera_capture)

# Remove camera object - ensures release of resources
del(camera)

print("Done")