Looking for a Simple Basic Project for Beginner to learn

February 16, 2023, 19:20

.thisisv

I have a raspberry pi 4 here. I have a breadboard, some LEDs, some resistors, a button I am looking for a simple beginner project, talk to me like I'm a 5 year old who can read with good documentation so that I can learn working with Raspberry Pi, creating something on a bread board, pin assignment and basic Python -> to get hardware to do something. I know some Python - I can also look up things when I get a good base down A little about breadboard LEDs but I'm not great - I was trying to get this stupid LED to light up and I did for a bit then it died. I just would like a step by step project that I can see a positive result and then branch out from there. Any suggestions would be appreciated.

ebr1965

actualy nvm. im no supposed to be sharing that stuff :(. ill point u at places

ebr1965

a pi board has this thing called "gpio" that stnads for general purpose io. thats how you get physical electrical signals from a pi

ebr1965


ebr1965

watch that you DONT FRY THE PI BECAUSE U HAVE THEWRONG VOLTAGES

ebr1965

the pins take around 3.3v although some take 5v. DO NOT INPUT 5V on a pin unless it specifically says it can take it

ebr1965


ebr1965

there a good chunck of features in the sys/class files

ebr1965

gpio is all that i really know about.

ebr1965

ill just go over bare bone use of the pins

ebr1965

note - there is a difference between gpio #'s and pin #'s

ebr1965

to send/receive signals from, say gpio17 (aka pin11), go to the "/sys/class/gpio" directory and type
 echo 17 >> export

ebr1965

this will create a new folder called "gpio17" that will be how you control that gpio

ebr1965

go into the folder and youll see

ebr1965


ebr1965

to tell the pin to receive signals type
echo in >> direction 
, replace "in" with "out" if you want to send a signal

ebr1965

either way, to control/read the signal. read or write the file called "value" in that same directory

ebr1965

reminder that DO NOT PUT MORE THAN 3.3v TO THE PIN or u will fry the board. there is a saftey that shuts down the os if you do but its a last resort

ebr1965

safest practice would be to use the 3.3v power supply pin from the board

ebr1965

the gpio pin settings are removed when the pi restarts

ebr1965

receiving signal demo)

ebr1965


ebr1965

then type
watch -n .5 "echo "signal:"; cat ./gpio17/value"

ebr1965

now if u connect gpio #17 on your raspberry pi board to a power supply(preferably the 3.3v supply pin on the board) the bash thing will show "signal: 1" when ocnnected, 0 otherwise

ebr1965

the "watch" command is just the bash equivilent of a while loop. in this case, runs every .5 of a second and prints out ("signal: " + [whatever is read form the value file])

ebr1965

to send a signal from the pin echo "out" instead of "in" and write 0 or 1 to the value file.

ebr1965

heres some example functions in C to do what I just described in code

ebr1965

void gpioOutput(int pin)
{
    FILE file;
    char str[35];
    file = fopen("/sys/class/gpio/export", "w");
    fprintf(file, "%d", pin);
    fclose(file);
    sprintf(str, "/sys/class/gpio/gpio%d/direction", pin);
    file = fopen(str, "w");
    fprintf(file, "out");
    fclose(file);
}

void gpioInput(int pin)
{
    FILE file;
    char str[35];
    file = fopen("/sys/class/gpio/export", "w");
    fprintf(file, "%d", pin);
    fclose(file);
    sprintf(str, "/sys/class/gpio/gpio%d/direction", pin);
    file = fopen(str, "w");
    fprintf(file, "in");
    fclose(file);
}

void gpioWrite(int pin, int value)
{
    FILE file;
    char str[35];
    sprintf(str, "/sys/class/gpio/gpio%d/value", pin);
    file = fopen(str, "w");
    fprintf(file, "%d", value);
    fclose(file);
}
  
int gpioRead(int pin)
{
    FILE file;
    int result;
    char str[30];
    sprintf(str, "/sys/class/gpio/gpio%d/value", pin);
    file = fopen(str, "rw");
    fscanf(file, "%d", &result);
    fclose(file);
    return result;
}

ebr1965

opening and closing files as much as these funcitons do is not good pratice

ebr1965

these should be simple to translate to python (gooogle is your firend)

ebr1965

example of connecting the pi to a bread board and using gpio to turn leds on/off

ebr1965


ebr1965

also tip. if u dont have the desk space for both a desktop and raspPi set up suggest u just ssh on to the pi through the desktop. best done with puTTy. u can find your pi's ip address as one of the ones that appear as the output of this powershell script(windows only)
## Q:\Test\2017\01\21\SO_41785413.ps1
>> ## Ping subnet
>> $Subnet = "192.168."
>> 1..254|ForEach-Object{
>>     Start-Process -WindowStyle Hidden ping.exe -Argumentlist "-n 1 -l 0 -f -i 2 -w 1 -4 $SubNet$_"
>> }
>> $Computers =(arp.exe -a | Select-String "$SubNet.dynam") -replace ' +',','|
>>   ConvertFrom-Csv -Header Computername,IPv4,MAC,x,Vendor|
>>                    Select Computername,IPv4,MAC
>>
>> ForEach ($Computer in $Computers){
>>   nslookup $Computer.IPv4|Select-String -Pattern "^Name:\s+([^\.]+).$"|
>>     ForEach-Object{
>>       $Computer.Computername = $_.Matches.Groups[1].Value
>>     }
>> }
>> $Computers | Format-Table
>> #$Computers | Out-Gridview
- altered version of https://stackoverflow.com/questions/41785413/use-powershell-to-get-device-names-and-their-ipaddress-on-a-home-network

.thisisv

Awesome thank you this is a perfect start I'll go over - I appreciate it