$ df -h
With option / display file system in /dev/root only.
$ df -h /
Display file system information with df command |
- Read file system information with Python
Display file system information with df command |
Node.js on Raspberry Pi |
<?php
list($system, $host, $kernel) = split(" ", exec("uname -a"), 5);
$meminfo = file("/proc/meminfo");
$infodetails = "<b>memory info</b><br/>";
for ($i = 0; $i < count($meminfo); $i++) {
list($item, $data) = split(":", $meminfo[$i], 2);
$item = chop($item);
$data = chop($data);
$infodetails .= $i." : ".$item." = ".$data."<br/>";
}
?>
<html>
<head>
<title>Hello Raspberry Pi</title>
</head>
<body>
<ul>
<li><?php echo $system ?></li>
<li><?php echo $host ?></li>
<li><?php echo $kernel ?></li>
</ul>
<?php echo $infodetails; ?><br/>
</body>
</html>
Display system and memory info of Raspberry Pi with PHP |
Raspberry Pi emulation for Windows |
Control the Raspberry Pi on-board LED using C language |
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#define BCM2708_PERI_BASE 0x20000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
#define LED_ACT 16
#define BLOCK_SIZE (4*1024)
int mem_fd;
void *gpio_map;
volatile unsigned *gpio;
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0
int init_io()
{
/* open /dev/mem */
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
printf("can't open /dev/mem \n");
return(-1);
}else{
printf("/dev/mem opened\n");
/* mmap GPIO */
gpio_map = mmap(
NULL, //Any adddress in our space will do
BLOCK_SIZE, //Map length
PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
MAP_SHARED, //Shared with other processes
mem_fd, //File to map
GPIO_BASE //Offset to GPIO peripheral
);
close(mem_fd);
printf("/dev/mem closed\n");
if (gpio_map == MAP_FAILED) {
printf("mmap error %d\n", (int)gpio_map);//errno also set!
return(-1);
}else{
printf("mmap Success.\n");
}
}
// Always use volatile pointer!
gpio = (volatile unsigned *)gpio_map;
return 0;
}
int main(){
if(init_io() == -1)
{
printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
return -1;
}
// must use INP_GPIO before we can use OUT_GPIO
INP_GPIO(LED_ACT);
OUT_GPIO(LED_ACT);
int repeat;
for (repeat=1; repeat<5; repeat++)
{
GPIO_SET = 1 << LED_ACT;
printf("LED OFF\n");
sleep(2);
GPIO_CLR = 1 << LED_ACT;
printf("LED ON\n");
sleep(1);
}
printf("- finished -\n");
return 0;
}
Control the on-board LED using Python |
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(16, GPIO.OUT)
for num in range(1, 5):
print num
GPIO.output(16, True) ##Turn OFF LED
print "LED OFF"
time.sleep(2)
GPIO.output(16, False) ##Turn ON LED
print "LED ON"
time.sleep(1)
Control the on-board LED on Raspberry Pi |
Linux command: id |
Linux command: groups |
add user to group |
list users in group |
BCM2835 ARM Peripherals Manual |
install Geany on Raspberry Pi |
Geany run on Raspberry Pi |
import serial
ser = serial.Serial('/dev/ttyACM1', 9600)
name_out = raw_input("Who are you?\n")
ser.write(name_out + "\n")
name_return = ser.readline()
print(name_return)
int pinLED = 13;
boolean ledon;
void setup() {
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
ledon = true;
digitalWrite(pinLED, ledon = !ledon);
}
void loop() {
if(Serial.available() > 0){
Serial.print("Hello ");
while(Serial.available()>0){
char charIn = (char)Serial.read();
Serial.print(charIn);
if (charIn == '\n')
break;
}
digitalWrite(pinLED, ledon = !ledon);
}
}
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
check kernel and GPU firmware version |
updated |
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
while 1:
print(ser.readline())
data output to Python Shell |
int pinLED = 13;
boolean ledon;
void setup() {
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
ledon = true;
}
void loop() {
Serial.print("Hello Pi\n");
digitalWrite(pinLED, ledon = !ledon);
delay(1000);
}
Arduino Due recognized as ttyACM0 in the example |
class helloPi
{
public static void main(String srgs[])
{
System.out.println("Hello Raspberry Pi");
}
}
java and javac on Raspberry Pi |
Usage: lsusb [options]...
List USB devices
-v, --verbose
Increase verbosity (show descriptors)
-s [[bus]:][devnum]
Show only devices with specified device and/or
bus numbers (in decimal)
-d vendor:[product]
Show only devices with the specified vendor and
product ID numbers (in hexadecimal)
-D device
Selects which device lsusb will examine
-t
Dump the physical USB device hierarchy as a tree
-V, --version
Show version of program
lsusb command |
lsusb without and with Arduino device attached |
Remote Ripple run on Android device, login Raspberry Pi |