/flash-rasbian-to-sd-with-C

A short C program to copy raspbian image file to the sd card.

Primary LanguageC

Flash Raspbian image to the SD card using C programming language

A short C program to copy raspbian image file to the sd card.

First make sure which drive is your SD card. In my case it was /dev/sda. You can use one of these commands:

ls -l /dev/sda*
lsblk -p
sudo fdisk -l
/dev/sda

first compile main.c

make

Before you try to copy .img file to SD card, make sure your SD card is formatted properly and has only one partition.

Run the compiled file as:

./copy <path to your original file> <path to your SD card device file>

Example:

./copy raspbian.img /dev/sda

Use sync command afterwards.

sync

Process should take a while.

##Some useful commands when working with Raspberry: We can take a picture with the same program we've used for copying .img file to SD.

Copy main.c to the RPi:

scp main.c pi@192.168.1.166:/home/pi

Compile a C file on the RPi using gcc:

pi@raspberrypi:~$ gcc main.c -Wall -o opt

Take an image from video0 (RPi camera) and save it in home folder.

pi@raspberrypi:~$  ./copy /dev/video0 image.jpg

Get image from the RPi to your PC. Run

scp pi@192.168.1.166:image.jpg /home/spehj/Desktop/