PiCHUB created by Mark Chin from Enutil Energy is a Raspberry Pi USB hub development board with Type C connector and Microcontroller. It is targeted for Raspberry Pi enthusiasts who would like to be able to connect the new USB-C cables and devices to their Raspberry Pi PCs including the smaller Raspberry Pi Zero.
Due to the limitations of Raspberry Pi the super speed data lines of USB Type C were not implemented. Instead the PiCHUB is designed for USB 2.0 specifications with speeds up to 480MB/s depending on the devices attached to the hub.
Hardware
The PiCHUB plugs into a Raspberry Pi via 26/40 pin header. If you are powering your Pi from a standard USB micro adapter the PiCHUB will power up when the Type A USB jumper cable is plugged in from the Pi USB port to PiCHUB upstream Type A USB port. This will provide power to the development board but is limited by the Pi's USB fuse. Devices can be plugged into all 3 Type A ports and the Type C port using the type C adapter provided.
The 15W USB Type C charger can be plugged directly into the Type C port while the Pi is already powered up and will switch the development board over to Type C power providing up to 3A of power. Port control of the Type C USB port is accomplished via a python script which must be run at the time of Pi bootup. Communication is done through I2C.
The PSOC 4 or ATTiny85V microcontroller was added to provide additional interfaces for the Pi and can be programmed with a PSOC MiniProg3 or Atmel USB programmer which is not included in the perks. Header P7 will allow you to isolate the power to the microcontroller when programming. PSOC chips are versatile programmable SOC's with anlog and digital blocks providing solutions for many applications with integrated components. Backers can also choose the option of an Atmel ATTiny85V microcontroller instead of the PSOC 4 which has a large community development support.
Software
The USB Type C Port Control software is open source and will be available for download on Enutil Energy's GitHub page. You will be able to modify and add additional python script for your applications. The USB port control software should be run upon bootup or prior to using the PiCHUB as detection and negotiation of the USB Type C port is required for use as a Device port or Charging port interchangeably. This can be added into the rc.local file to run at bootup. Python-smbus library must be installed on your Pi in order for the I2C script to work.
Features of the Raspberry Pi PiCHUB hub include :
– Switch on the Fly USB Type C power 15W @ 5V
– Digital and Analog to the Microcontroller
– 1 Upstream, 3 Downstream and 1 Dual Role Type C Port
– I2C Communication from Pi to Microcontroller and Type C Port Controller
– Plugs directly into Rasp Pi A/B/B+/3/Zero with USB jumper cable
– 3.3V and 5V output connectors for external supply to devices
– USB power or device through one Dual Role Port (DRP)
– High Speed USB 480Mbits/s
– PSOC 4 ARM Cortex M0 16K Flash 16MHz
– Or ATTiny85V 8Bit 8K Flash
– 3.3” Wide x 2.2″ High
– Included Stackable Header 26/40 pin
– Plug in USB Type C devices to Communicate
To learn more about the new PiCHUB - USB Type C HUB for Raspberry Pi and PiZero do visit their Kickstarter page and make a pledge if you are interested. CAD $14,000 is required to take the new PiCHUB USB-C hub into production.
Due to the limitations of Raspberry Pi the super speed data lines of USB Type C were not implemented. Instead the PiCHUB is designed for USB 2.0 specifications with speeds up to 480MB/s depending on the devices attached to the hub.
Hardware
The PiCHUB plugs into a Raspberry Pi via 26/40 pin header. If you are powering your Pi from a standard USB micro adapter the PiCHUB will power up when the Type A USB jumper cable is plugged in from the Pi USB port to PiCHUB upstream Type A USB port. This will provide power to the development board but is limited by the Pi's USB fuse. Devices can be plugged into all 3 Type A ports and the Type C port using the type C adapter provided.
The 15W USB Type C charger can be plugged directly into the Type C port while the Pi is already powered up and will switch the development board over to Type C power providing up to 3A of power. Port control of the Type C USB port is accomplished via a python script which must be run at the time of Pi bootup. Communication is done through I2C.
The PSOC 4 or ATTiny85V microcontroller was added to provide additional interfaces for the Pi and can be programmed with a PSOC MiniProg3 or Atmel USB programmer which is not included in the perks. Header P7 will allow you to isolate the power to the microcontroller when programming. PSOC chips are versatile programmable SOC's with anlog and digital blocks providing solutions for many applications with integrated components. Backers can also choose the option of an Atmel ATTiny85V microcontroller instead of the PSOC 4 which has a large community development support.
Software
The USB Type C Port Control software is open source and will be available for download on Enutil Energy's GitHub page. You will be able to modify and add additional python script for your applications. The USB port control software should be run upon bootup or prior to using the PiCHUB as detection and negotiation of the USB Type C port is required for use as a Device port or Charging port interchangeably. This can be added into the rc.local file to run at bootup. Python-smbus library must be installed on your Pi in order for the I2C script to work.
Features of the Raspberry Pi PiCHUB hub include :
– Switch on the Fly USB Type C power 15W @ 5V
– Digital and Analog to the Microcontroller
– 1 Upstream, 3 Downstream and 1 Dual Role Type C Port
– I2C Communication from Pi to Microcontroller and Type C Port Controller
– Plugs directly into Rasp Pi A/B/B+/3/Zero with USB jumper cable
– 3.3V and 5V output connectors for external supply to devices
– USB power or device through one Dual Role Port (DRP)
– High Speed USB 480Mbits/s
– PSOC 4 ARM Cortex M0 16K Flash 16MHz
– Or ATTiny85V 8Bit 8K Flash
– 3.3” Wide x 2.2″ High
– Included Stackable Header 26/40 pin
– Plug in USB Type C devices to Communicate
To learn more about the new PiCHUB - USB Type C HUB for Raspberry Pi and PiZero do visit their Kickstarter page and make a pledge if you are interested. CAD $14,000 is required to take the new PiCHUB USB-C hub into production.
7 segments can be driven using many different techniques in conjunction with software and hardware. Multiplexing is one of the most popular methods used to drive a 7 segment display when there are limited no of I/O pins.It uses the concept of POV(persistence of vision) where the human brain cannot detect the flickering of display when the refresh rate is very high(~50Hz).In this method the fundamental logic is to enable or disable the segment blocks at a very high speed at precise time slices.
In case of Raspberry Pi there are limited no of I/O pins, hence we will use multiplexing. WiringPi is perfect for this job as it uses Arduino like code and the code executes at a higher priority. Display used in this example is of common cathode type.Make sure you have the right 7 segment display,else you will end up getting random segments turned on.For pin mapping check the code below:-
Compile the code as...
gcc -o display segment.c -L/usr/local/lib -lwiringPi
Now execute it...
sudo ./display
In case of Raspberry Pi there are limited no of I/O pins, hence we will use multiplexing. WiringPi is perfect for this job as it uses Arduino like code and the code executes at a higher priority. Display used in this example is of common cathode type.Make sure you have the right 7 segment display,else you will end up getting random segments turned on.For pin mapping check the code below:-
Code:-
#include <wiringPi.h> #include <stdio.h> #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW #define SEGMENT_ON LOW #define SEGMENT_OFF HIGH int SEGMENT_1=7; int SEGMENT_2=11; int SEGMENT_3=13; int SEGMENT_4=15; int SEGMENT_A=3; int SEGMENT_B=5; int SEGMENT_C=18; int SEGMENT_D=19; int SEGMENT_E=23; int SEGMENT_F=24; int SEGMENT_G=25; void display_number(int num) { pinMode(SEGMENT_1,OUTPUT); pinMode(SEGMENT_2,OUTPUT); pinMode(SEGMENT_3,OUTPUT); pinMode(SEGMENT_4,OUTPUT); long start=millis(); for(int i=4;i>0;i--) { switch(i) { case 1: digitalWrite(SEGMENT_1,DIGIT_ON); break; case 2: digitalWrite(SEGMENT_2,DIGIT_ON); break; case 3: digitalWrite(SEGMENT_3,DIGIT_ON); break; case 4: digitalWrite(SEGMENT_4,DIGIT_ON); break; } print_number(num%10); num/=10; delayMicroseconds(DISPLAY_BRIGHTNESS); print_number(10); digitalWrite(SEGMENT_1,DIGIT_OFF); digitalWrite(SEGMENT_2,DIGIT_OFF); digitalWrite(SEGMENT_3,DIGIT_OFF); digitalWrite(SEGMENT_4,DIGIT_OFF); } while((millis()-start)<10); } void print_number(int num) { pinMode(SEGMENT_A,OUTPUT); pinMode(SEGMENT_B,OUTPUT); pinMode(SEGMENT_C,OUTPUT); pinMode(SEGMENT_D,OUTPUT); pinMode(SEGMENT_E,OUTPUT); pinMode(SEGMENT_F,OUTPUT); pinMode(SEGMENT_G,OUTPUT); switch(num) { case 0: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_ON); digitalWrite(SEGMENT_E,SEGMENT_ON); digitalWrite(SEGMENT_F,SEGMENT_ON); digitalWrite(SEGMENT_G,SEGMENT_OFF); break; case 1: digitalWrite(SEGMENT_A,SEGMENT_OFF); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_OFF); digitalWrite(SEGMENT_E,SEGMENT_OFF); digitalWrite(SEGMENT_F,SEGMENT_OFF); digitalWrite(SEGMENT_G,SEGMENT_OFF); break; case 2: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_OFF); digitalWrite(SEGMENT_D,SEGMENT_ON); digitalWrite(SEGMENT_E,SEGMENT_ON); digitalWrite(SEGMENT_F,SEGMENT_OFF); digitalWrite(SEGMENT_G,SEGMENT_ON); break; case 3: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_ON); digitalWrite(SEGMENT_E,SEGMENT_OFF); digitalWrite(SEGMENT_F,SEGMENT_OFF); digitalWrite(SEGMENT_G,SEGMENT_ON); break; case 4: digitalWrite(SEGMENT_A,SEGMENT_OFF); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_OFF); digitalWrite(SEGMENT_E,SEGMENT_OFF); digitalWrite(SEGMENT_F,SEGMENT_ON); digitalWrite(SEGMENT_G,SEGMENT_ON); break; case 5: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_OFF); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_ON); digitalWrite(SEGMENT_E,SEGMENT_OFF); digitalWrite(SEGMENT_F,SEGMENT_ON); digitalWrite(SEGMENT_G,SEGMENT_ON); break; case 6: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_OFF); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_ON); digitalWrite(SEGMENT_E,SEGMENT_ON); digitalWrite(SEGMENT_F,SEGMENT_ON); digitalWrite(SEGMENT_G,SEGMENT_ON); break; case 7: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_OFF); digitalWrite(SEGMENT_E,SEGMENT_OFF); digitalWrite(SEGMENT_F,SEGMENT_OFF); digitalWrite(SEGMENT_G,SEGMENT_OFF); break; case 8: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_ON); digitalWrite(SEGMENT_E,SEGMENT_ON); digitalWrite(SEGMENT_F,SEGMENT_ON); digitalWrite(SEGMENT_G,SEGMENT_ON); break; case 9: digitalWrite(SEGMENT_A,SEGMENT_ON); digitalWrite(SEGMENT_B,SEGMENT_ON); digitalWrite(SEGMENT_C,SEGMENT_ON); digitalWrite(SEGMENT_D,SEGMENT_ON); digitalWrite(SEGMENT_E,SEGMENT_OFF); digitalWrite(SEGMENT_F,SEGMENT_ON); digitalWrite(SEGMENT_G,SEGMENT_ON); break; case 10: digitalWrite(SEGMENT_A,SEGMENT_OFF); digitalWrite(SEGMENT_B,SEGMENT_OFF); digitalWrite(SEGMENT_C,SEGMENT_OFF); digitalWrite(SEGMENT_D,SEGMENT_OFF); digitalWrite(SEGMENT_E,SEGMENT_OFF); digitalWrite(SEGMENT_F,SEGMENT_OFF); digitalWrite(SEGMENT_G,SEGMENT_OFF); break; } } int main(void) { printf("7 Segment Multiplexing using Raspberry Pi\n") ; if(getuid()!=0) //wiringPi requires root privileges { printf("Error:wiringPi must be run as root.\n"); return 1; } if(wiringPiSetup()==-1) { printf("Error:wiringPi setup failed!\n"); return 1; } int counter=0; for(;;) { display_number(counter++); delay(1000); if(counter>9999) counter=0; } return 0; }
Compile the code as...
gcc -o display segment.c -L/usr/local/lib -lwiringPi
Now execute it...
sudo ./display
With only one hardware PWM pin on Raspberry Pi it can be quite a problem with Arduino users like me.There are various hardware solutions available to overcome this problem.Many ADC(analog to digital converters) IC are available which can be interfaced via I2C bus.In this post I will be using WiringPi library which can bit-bang any GPIO pins and generate PWM signal. Even though the PWM signals are generated by individual threads with high priority using a real-time scheduler, there may be instances where it may get temporarily descheduled for a fraction of a second and cause jitters.
Installing the Library:-
WiringPi is maintained under GIT for ease of change tracking.If you do not have GIT installed, then under any of the Debian releases, you can install it with-
sudo apt-get install git-core
To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi
If you have already used the clone operation for the first time, then
cd wiringPi
git pull origin
Will fetch an updated version then you can re-run the build script below.
To build/install there is a new simplified script:
cd wiringPi
./build
The new build script will compile and install it all for you – it does use the sudo command at one point, so you may wish to inspect the script before running it.
Example Code:-
This code uses both the hardware and software PWM functions.
Installing the Library:-
WiringPi is maintained under GIT for ease of change tracking.If you do not have GIT installed, then under any of the Debian releases, you can install it with-
sudo apt-get install git-core
To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi
If you have already used the clone operation for the first time, then
cd wiringPi
git pull origin
Will fetch an updated version then you can re-run the build script below.
To build/install there is a new simplified script:
cd wiringPi
./build
The new build script will compile and install it all for you – it does use the sudo command at one point, so you may wish to inspect the script before running it.
Example Code:-
This code uses both the hardware and software PWM functions.
//////--------------------------------------------------------------------------- ////// Name: pwm.c ////// Compiled with: gcc pwm.c -I/usr/local/include -L/usr/local/lib -lwiringPi -lpthread -o pwm ////// Schematic: .------. ////// | o o | ////// RPi | o o |12 ////// | o o-|-----(->|)-----\/\/\/\--o GND ////// | o o |11 LED1 220 ////// | o o-|-----(->|)-----\/\/\/\--o GND ////// | o o | LED2 220 ////// | o o-| ////// ////// Notes: //////--------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <wiringPi.h> #include <softPwm.h> void control_event(int sig); int HARD_PWM_PIN=1; //Hardware PWM Pin(GPIO18-12) int SOFT_PWM_PIN=0; //Software PWM Pin(GPIO0-11) int DELAY_MS=10; int main(void) { (void)signal(SIGINT,control_event); (void)signal (SIGQUIT,control_event); printf("Hardware and software based PWM test on LED\n"); if(getuid()!=0) //wiringPi requires root privileges { printf("Error:wiringPi must be run as root.\n"); return 1; } if(wiringPiSetup()==-1) { printf("Error:wiringPi setup failed.\n"); return 1; } pinMode(HARD_PWM_PIN,PWM_OUTPUT); //setup hardware pwm softPwmCreate(SOFT_PWM_PIN,0,100); //setup software pwm pin int up; int down; while(1) { for(up=1;up=5;down--) { pwmWrite(HARD_PWM_PIN,down); softPwmWrite(SOFT_PWM_PIN,down); delay(DELAY_MS*2); } delay(DELAY_MS*5); } } void control_event(int sig) { printf("\b\bExiting...\n"); pwmWrite(HARD_PWM_PIN,0); softPwmWrite(SOFT_PWM_PIN,0); delay(100); //wait a little for the pwm to finish write exit(0); }Limitations:- To minimize CPU usage the minimum default pulse width is set to 100μs thereby generating a PWM of 100 Hz. Lowering the range can give you a higher frequency at an expense of resolution and vice versa. Delays less than 100μs will dramatically increase the CPU usage and controlling other pins would be impossible.However, within these limitations controlling an LED or Motor is quite practical.
In this tutorial, I will demonstrate the following:-
1. Login through ssh
2. Changing pi's password
3. Navigating through file-system
4. Copying files on network
5. Shutdown, Reboot pi
6. Writing, compiling a C program
Download Notes
1. Login through ssh
2. Changing pi's password
3. Navigating through file-system
4. Copying files on network
5. Shutdown, Reboot pi
6. Writing, compiling a C program
Download Notes