Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Tuesday, August 23, 2022

Linux Commands For Raspberry Pi Users - Part#1

If you are venturing into Raspberry Pi (RPi), without a good hold on Linux, this series of articles might be of interest to you. Let me present a list of useful Linux commands those will be handy for you to operate from the RPi Command Line Interface (CLI). Especially if you have loaded the Raspberry Pi OS Lite version of the OS image, which is the leaner version of the OS, you will be left with the only option of operating from the CLI.

First thought of mentioning a few basics about the directory structure for the new users. As the Raspberry Pi OS is based on Linux, everything is organized under the "root" directory, which is denoted as "/".  The working directory for an user is usually at a location "/home/<username>". If the username is "pi", then the working directory for that user would be "/home/pi". Note that, this working directory is under the root directory "/". 

The working directory for a particular user, which is know as the home directory for that user is denoted as "~". Once you login to the Raspberry Pi, you will be in your working directory "~". To see which directory you are in currently, type:

$ pwd 

The above command reveals the "present working directory" to you.

You could change directory to the root directory by typing: 

$ cd /

But it is worth cautioning here, avoid messing up with the root directory unless you know what you are doing. We could move back to the home directory by using the command:

$ cd ~

Or, simply, type:

$ cd

This might be useful to know that your previous working directory is stored in a variable $OLDPWD. In case, you want to change to the previous working directory, type the command:

$ cd $OLDPWD

Next, you might want to know the content of a particular directory. The following command is a quick one to know the other directories and files stored in a directory.

$ ls [flags] [directory path]

The flags, which are optional, control the format and the level of details that will be displayed about the content. The path for the directory for which this command is to be executed is also option. If the path is omitted, the list command will be executed for the present working directory.

To learn more about the options available for the flags, type the following command:  

$ man ls

The above command brings out the manual of the command "ls".

Let us now see a handful of frequently used flags and how powerful those could be. Executing the "ls" command without any flags, would just show the names of the directories and files stored under the present working directory. Note that, the hidden items are not shown. In order to show all directories and files including the hidden ones, you need to use the option "-a": 

$ ls -a

Any file that begins with a "." is considered a hidden file in the Linux environment.

To know more details about the file or the directory, type the following command:

$ ls -l

The flag "-l" reveals the detailed information such as the owners of the file/directory, permission, date of last modification, size in bytes etc. along with the name of the file or directory.

If you need to see the subdirectories under each of the directories in the present path, type:

$ ls -R

The "-R" (capital R) flag in the "ls" command will list all directories with their corresponding subdirectories down to the last file. Obviously, this command will also show the files in the current directory.

Now let us see how we could list the content of the present directory by sorting them by their size and time. Use the flag "-S" (capital S) to sort the content with respect to their sizes, in descending order (biggest to smallest):

$ ls -S

Similarly, use the flag "-t" (small t) to sort the content according to the time last modified, in descending order (most recent first).

$ ls -t

If you want to reverse the order, simply add "r" to the above two commands:

$ ls -Sr

$ ls -tr

The above two commands will reverse the order of sorting respectively. Now it is interesting to note here, you could combine multiple flags as shown above. However, the above commands will not show the size or time information. In order to show those information too, you could combine "-l" flag with the respecting commands, for example:

$ ls -S -l

OR:

$ ls -Sl

OR:

$ ls -lS

etc.

Is not it so flexible and powerful feature of Linux? I am sure you will love it eventually.

Now, could you please try the command yourself:

$ ls -lSr

What does the above command yield?

In the following part of this series we will see the commands to create, copy and move files/directories.

Thursday, April 7, 2022

Test your knowledge in Arduino and ATmega328P: QUIZ# 2

 


[Picture Source: https://content.arduino.cc/assets/Pinout-UNOrev3_latest.png]

Arduino Quiz# 2

1. As the pins A0 to A5 are configured as Analog Input pins on Arduino UNO, it is not necessary to declare the pins as input pins using the function pinMode(). State true or false.

A. True
B. False

2. Which one of the following statements is not correct about the microcontroller ATmega328P?

A. The IO port registers PORTx and DDRx are read/write types, whereas the PINx register is a read-only type
B. The six of the PORTC pins are configured as Analog Input on Arduino UNO
C. All ports B, C and D could be configured as digital input/output along with other functions
D. The ADC inside ATmega328P is six channel 10-bit ADC
E. None of the above

3. The IO ports of ATmega328P are controlled and accessed by three registers:

A. DDRx, PORTx and LOADx
B. DDRx, PINx and LOADx
C. PORTx, PINx and DDRx
D. PINx, PUSHx and POPx
E. None of the above

4. The IO port registers are basically built out of:

A. Diodes
B. D-FFs
C. RS FFs
D. Wire junctions
E. None of the above

5. Stack Pointer register increments by 1 during the execution of a POP instruction execution and decrements by 1 during PUSH instruction execution.

A. True
B. False

6. If the ADC of ATmega328P on Arduino UNO is configured to use the internal voltage reference, the analog values 0 and 1023 read on pin A0 using the analogRead() function would correspond to:

A. 0V and 5V respectively
B. 0V and 1.1V respectively
C. 0.1V and 4V respectively
D. 0V and 4V respectively
E. None of the above

7. STACK has majorly two uses. Those are:

A. as temporary storage for variables, the values which are needed to be restored later and to store the Stack Pointer
B. to store the return address during function calls and as temporary storage for variables, the values which are needed to be restored later
C. to manipulate data during program execution and to store the return address during function calls
D. to store instructions and to store the addressed of the functions

8. Assume that the ADC of ATmega328P on Arduino UNO has the default configuration for reference voltage (AREF). What is the LSB in terms of voltage?

A. 4.25 mV
B. 0.12 V
C. 4.88 mV
D. 3.26 mV
E. None of the above

9. Data memory read access is faster than the same for program memory.

A. True
B. False

10. PINx register can be read or be written as well by the program. State whether true or false:

A. True
B. False

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Answers for Quiz# 1 (in the previous post):

1. B     2. A     3. C     4. A.    5. A    6. A    7. A    8. A    9. C    10. D