Difference between revisions of "Raspberry"

From Random Stuff
Jump to navigation Jump to search
Line 59: Line 59:
 
  "
 
  "
  
−
  # Now we will edit the second configration file and we will make sure the MACHINE is set to our target board.
+
  # Now we will edit the second configuration file and we will make sure the MACHINE is set to our target board.
 
  gedit conf/local.conf
 
  gedit conf/local.conf
  
Line 78: Line 78:
  
  
−
= Flashing the image on the sdcard =
+
= Flashing the image onto the sdcard =
  
 
To find the image go from your build folder in: '''tmp/deploy/images/raspberrypi4/'''
 
To find the image go from your build folder in: '''tmp/deploy/images/raspberrypi4/'''

Revision as of 15:34, 22 July 2021

Setup environment

Assuming a debian distribution, install the following dependencies:

 sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
     build-essential chrpath socat cpio python3 python3-pip python3-pexpect \
     xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \
     pylint3 xterm



Fetching the sources

Create a new project directory in your workspace folder. For example in ~/workspace

# Create the new project structure:
mkdir -p raspberry/sources


# Enter the sources folder
cd raspberry/sources


# And clone the following repositories
git clone git://git.yoctoproject.org/poky -b hardknott
git clone https://git.openembedded.org/meta-openembedded -b hardknott
git clone git://git.yoctoproject.org/meta-raspberrypi -b hardknott



Configuring the project

# Move back to the project folder and source the environment
cd -
. sources/poky/oe-init-build-env


Notice the you are now in a new build directory. ie. ~/workspace/raspberry/build, and some new configuration files have been added in a conf folder.

# Edit the bblayer.conf
gedit conf/bblayers.conf

and make sure it now has the following content for BBLAYERS:

# Make sure the following variable has the following layers set:
BBLAYERS ?= " \
  ${TOPDIR}/../sources/poky/meta \
  ${TOPDIR}/../sources/poky/meta-poky \
  ${TOPDIR}/../sources/poky/meta-yocto-bsp \
  ${TOPDIR}/../sources/meta-raspberrypi \
  ${TOPDIR}/../sources/meta-openembedded/meta-oe \
  ${TOPDIR}/../sources/meta-openembedded/meta-multimedia \
  ${TOPDIR}/../sources/meta-openembedded/meta-networking \
  ${TOPDIR}/../sources/meta-openembedded/meta-python \
"
# Now we will edit the second configuration file and we will make sure the MACHINE is set to our target board.
gedit conf/local.conf
# Make sure the following machine is set:
MACHINE ?= "raspberrypi4"


Building an image

To build an image we will run:

bitbake core-image-full-cmdline

'Note': A rough way to get an idea of what other images you may build would be to run from the sources folder:

find . -wholename *images/*.bb

However for the moment core-image-full-cmdline satisfies our needs.


Flashing the image onto the sdcard

To find the image go from your build folder in: tmp/deploy/images/raspberrypi4/

If we’ve build core-image-full-cmdline you should see here a file named: core-image-full-cmdline.wic.bz2


# Extract the file
bzip2 -df core-image-full-cmdline.wic.bz2

Now you should see that core-image-full-cmdline.wic.bz2 dissapeared and there is a new file named: core-image-full-cmdline.wic


Insert the sd card in the pc and check the device to which it corresponds using:

lsblk -p


If you are unsure. Unplug the sdcard, run the command again check which device dissapears/appears

Possible sample output:

NAME             MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
/dev/loop0         7:0    0 215.4M  1 loop /snap/rpi-imager/170
/dev/loop1         7:1    0  99.2M  1 loop /snap/core/10958
/dev/loop2         7:2    0  61.7M  1 loop /snap/core20/975
/dev/loop3         7:3    0  61.7M  1 loop /snap/core20/1026
/dev/loop4         7:4    0  99.4M  1 loop /snap/core/11316
/dev/loop5         7:5    0 196.5M  1 loop /snap/rpi-imager/184
/dev/sda           8:0    0 111.8G  0 disk 
├─/dev/sda1        8:1    0  37.3G  0 part /
├─/dev/sda2        8:2    0     1K  0 part 
├─/dev/sda5        8:5    0   3.7G  0 part [SWAP]
└─/dev/sda6        8:6    0  70.8G  0 part /home
/dev/sdb           8:16   1 698.7G  0 disk 
├─/dev/sdb1        8:17   1   200G  0 part /media/nicu/6E56907E5690492B1
├─/dev/sdb2        8:18   1   200G  0 part /media/nicu/Local Disk3
├─/dev/sdb3        8:19   1   201G  0 part /media/nicu/Local Disk2
├─/dev/sdb4        8:20   1     1K  0 part 
├─/dev/sdb5        8:21   1   4.6G  0 part 
└─/dev/sdb6        8:22   1  93.1G  0 part /media/nicu/DebianPart3
/dev/mmcblk0     179:0    0    30G  0 disk 
├─/dev/mmcblk0p1 179:1    0  50.3M  0 part /media/nicu/boot
└─/dev/mmcblk0p2 179:2    0 192.4M  0 part /media/nicu/root


In the above example the sdcard is: /dev/mmcblk0 and it’s a 32 GB card. It has two partitions: mmcblk0p1 and mmcblk0p2.

Now that we have identified the image and the device, we will have to write the image.

Don’t proceed if you are unsure you have the right device, as you might erase the data on your laptop. The data on the sdcard will be erased.

So if all is ok run the following command:

dd if=<raspberry image> of=<device> bs=4M conv=fsync

so in my case:

dd if=core-image-full-cmdline.wic of=/dev/mmcblk0 bs=4M conv=fsync

The process shall take around 1 minute, wait until it finishes.

Once done plug the device in the raspbery and power it on.


Raspberry pinout

Raspberry pi4 pinout


Basic led

There are two types of rgb leds: with common cathod or common anode. The longest pin is usually the common one.


Led pins



Control GPIO’s

# Export pin to userspace
echo "18" > /sys/class/gpio/export 
# Set pin 18 as an output
echo "out" > /sys/class/gpio/gpio18/direction
# Set pin 18 to high
echo "1" > /sys/class/gpio/gpio18/value
# Set pin 18 to low
echo "0" > /sys/class/gpio/gpio18/value

Putting it all together

For my case I chose pin 18(the 6th pin on the right side). this pin will be connected to the anod (longest pin of the led) and I will connect any of the other leds to a ground(ex. 3rd pin on the right side).

When the pin is high the led should light up. When it’s low, it should shut down.


Connect to the device with a patch cord cable, and use a command like nmap to find the address of the device:

ex. nmap -sP 192.168.0.0/24

Connect to the device through ssh:

ex. ssh root@192.168.0.151

One led connection