60

Is there a way of determining whether the current Raspberry Pi is either a 2 Model B and 3 with Raspbian Jessie Lite 8.0?

This is because I have a particular bootstrap.sh written in Bash where it needs to set the attribute txpower for a Wi-Fi USB dongle (here, Raspberry Pi 2) using a Ralink RT5370 chipset driver.

I set the Wireless attributes using iwconfig (which, I know is deprecated, but it currently gets the job done, so I am not changing it).

Since, in Raspberry Pi 3 the internal Wi-Fi chipset is a bcm-based chipset which will not let the following command execute:

iwconfig wlan0 mode ad-hoc channel 6 essid myadhoc txpower 0dBm

With Raspberry Pi 3 the above mentioned command works just by removing dBm from the above mentioned command:

iwconfig wlan0 mode ad-hoc channel 6 essid myadhoc txpower 0

I would like to add a check whether the Raspberry Pi model is 2 or 3 using Bash.

Any hints?

In case, someone wants to go through the bootstrap.sh: Bootstrapping for TWIN

Notes

  • I checked that dBm is not required, also in the case of the Raspberry Pi 2 with the Ralink chipset hence for non-ambiguity one can use the same command for both the Raspberry Pis viz.

    iwconfig wlan0 mode ad-hoc channel 6 essid myadhoc txpower 0
    
  • It is interesting to note that for external Wi-Fi USB dongles one needs to perform the following (for Raspberry Pi 2):

    ifconfig wlan0 down
    iwconfig wlan0 mode ad-hoc channel 6 essid myadhoc txpower 0
    ifconfig wlan0 up
    

    while as for inbuilt Wi-Fi modules (Raspberry Pi 3) there is no need for ifconfig up and down. Just the straightforward iwconfig command works.

fearless_fool
  • 593
  • 1
  • 4
  • 15
Shan-Desai
  • 1,541
  • 2
  • 13
  • 28

7 Answers7

110
cat /proc/device-tree/model

returns something like

Raspberry Pi 3 Model B Rev 1.2
SBF
  • 1,224
  • 2
  • 10
  • 9
23

By CPU Type

You could check the RPi version with the command, uname. The different RPi versions have different CPU architectures. The RPi 2 has an arm7, whereas the 3 has an arm8.

uname -m

By Hardware Revision

If you need to be more specific, you can check the revision entry from the output of cat /proc/cpuinfo. If you want to just exact the revision number, the following command should do it:

cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}'

Revision Numbers

This webpage has a handy chart that I've copied here.

enter image description here

Jacobm001
  • 11,904
  • 7
  • 47
  • 58
11

There are many methods (of varying reliability) to determine this. One of the most complete and reliable is gpio -v which produces the following output.

gpio version: 2.44
Copyright (c) 2012-2017 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi 3, Revision: 02, Memory: 1024MB, Maker: Embest 
  * Device tree is enabled.
  *--> Raspberry Pi 3 Model B Rev 1.2
  * This Raspberry Pi supports user-level GPIO access.

This could be done more elegantly by writing a simple program, using the functions provided by wiringpi. These are well documented, and the source is readily available.

The script in https://raspberrypi.stackexchange.com/a/85016/8697 shows comprehensive information about your Pi and OS.

Milliways
  • 62,573
  • 32
  • 113
  • 225
3

You could also use tool called pinout

enter image description here

3

I don't have enough rep to comment on @Andy Delgado reply but heres a different version of his code using some newer bash features.

function check_pi_version() {
  local -r REVCODE=$(awk '/Revision/ {print $3}' /proc/cpuinfo)
  local -rA REVISIONS=(
    [0002]="Model B Rev 1, 256 MB RAM"
    [0003]="Model B Rev 1 ECN0001, 256 MB RAM"
    [0004]="Model B Rev 2, 256 MB RAM"
    [0005]="Model B Rev 2, 256 MB RAM"
    [0006]="Model B Rev 2, 256 MB RAM"
    [0007]="Model A, 256 MB RAM"
    [0008]="Model A, 256 MB RAM"
    [0009]="Model A, 256 MB RAM"
    [000d]="Model B Rev 2, 512 MB RAM"
    [000e]="Model B Rev 2, 512 MB RAM"
    [000f]="Model B Rev 2, 512 MB RAM"
    [0010]="Model B+, 512 MB RAM"
    [0013]="Model B+, 512 MB RAM"
    [900032]="Model B+, 512 MB RAM"
    [0011]="Compute Module, 512 MB RAM"
    [0014]="Compute Module, 512 MB RAM"
    [0012]="Model A+, 256 MB RAM"
    [0015]="Model A+, 256 MB or 512 MB RAM"
    [a01041]="2 Model B v1.1, 1 GB RAM"
    [a21041]="2 Model B v1.1, 1 GB RAM"
    [a22042]="2 Model B v1.2, 1 GB RAM"
    [90092]="Zero v1.2, 512 MB RAM"
    [90093]="Zero v1.3, 512 MB RAM"
    [0x9000C1]="Zero W, 512 MB RAM"
    [a02082]="3 Model B, 1 GB RAM"
    [a22082]="3 Model B, 1 GB RAM"
  )

  echo "Raspberry Pi ${REVISIONS[${REVCODE}]} (${REVCODE})"
}

Aside: REVISIONS is defined inside of a function since I use it over ssh i.e. ssh some-host "$(declare -f); check_pi_version"

Takle
  • 31
  • 3
2

I created a bash script that will provide the model info based on the Revision.

If you make it better, please let me know.

#!/bin/bash
# which_pi.bash
# BASH Script to display Pi Hardware version based on info found in /proc/cpuinfo
# Andy Delgado - April 11, 2017
# Info gleaned from
# http://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version

REVCODE=$(sudo cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^ *//g' | sed 's/ *$//g')

if [ "$REVCODE" = "0002" ]; then
    PIMODEL="Raspberry Pi Model B Rev 1, 256 MB RAM"
fi

if [ "$REVCODE" = "0003" ]; then
    PIMODEL="Raspberry Pi Model B Rev 1 ECN0001, 256 MB RAM"
fi

if [ "$REVCODE" = "0004" ]; then
    PIMODEL="Raspberry Pi Model B Rev 2, 256 MB RAM"
fi

if [ "$REVCODE" = "0005" ]; then
    PIMODEL="Raspberry Pi Model B Rev 2, 256 MB RAM"
fi

if [ "$REVCODE" = "0006" ]; then
    PIMODEL="Raspberry Pi Model B Rev 2, 256 MB RAM"
fi

if [ "$REVCODE" = "0007" ]; then
    PIMODEL="Raspberry Pi Model A, 256 MB RAM"
fi

if [ "$REVCODE" = "0008" ]; then
    PIMODEL="Raspberry Pi Model A, 256 MB RAM"
fi

if [ "$REVCODE" = "0009" ]; then
    PIMODEL="Raspberry Pi Model A, 256 MB RAM"
fi

if [ "$REVCODE" = "000d" ]; then
    PIMODEL="Raspberry Pi Model B Rev 2, 512 MB RAM"
fi

if [ "$REVCODE" = "000e" ]; then
    PIMODEL="Raspberry Pi Model B Rev 2, 512 MB RAM"
fi

if [ "$REVCODE" = "000f" ]; then
    PIMODEL="Raspberry Pi Model B Rev 2, 512 MB RAM"
fi

if [ "$REVCODE" = "0010" ]; then
    PIMODEL="Raspberry Pi Model B+, 512 MB RAM"
fi

if [ "$REVCODE" = "0013" ]; then
    PIMODEL="Raspberry Pi Model B+, 512 MB RAM"
fi

if [ "$REVCODE" = "900032" ]; then
    PIMODEL="Raspberry Pi Model B+, 512 MB RAM"
fi

if [ "$REVCODE" = "0011" ]; then
    PIMODEL="Raspberry Pi Compute Module, 512 MB RAM"
fi

if [ "$REVCODE" = "0014" ]; then
    PIMODEL="Raspberry Pi Compute Module, 512 MB RAM"
fi

if [ "$REVCODE" = "0012" ]; then
    PIMODEL="Raspberry Pi Model A+, 256 MB RAM"
fi

if [ "$REVCODE" = "0015" ]; then
    PIMODEL="Raspberry Pi Model A+, 256 MB or 512 MB RAM"
fi

if [ "$REVCODE" = "a01041" ]; then
    PIMODEL="Raspberry Pi 2 Model B v1.1, 1 GB RAM"
fi

if [ "$REVCODE" = "a21041" ]; then
    # a21041 (Embest, China)
    PIMODEL="Raspberry Pi 2 Model B v1.1, 1 GB RAM"
fi

if [ "$REVCODE" = "a22042" ]; then
    PIMODEL="Raspberry Pi 2 Model B v1.2, 1 GB RAM"
fi

if [ "$REVCODE" = "90092" ]; then
    PIMODEL="Raspberry Pi Zero v1.2, 512 MB RAM"
fi

if [ "$REVCODE" = "90093" ]; then
    PIMODEL="Raspberry Pi Zero v1.3, 512 MB RAM"
fi

if [ "$REVCODE" = "0x9000C1" ]; then
    PIMODEL="Raspberry Pi Zero W, 512 MB RAM"
fi

if [ "$REVCODE" = "a02082" ]; then
    PIMODEL="Raspberry Pi 3 Model B, 1 GB RAM"
fi

if [ "$REVCODE" = "a22082" ]; then
    PIMODEL="Raspberry Pi 3 Model B, 1 GB RAM"
fi

echo "$PIMODEL ($REVCODE)"
Eugen
  • 488
  • 3
  • 13
-2

Simple way : dmesg | grep "Machine model:"