Labels

Arduino (1) Bugs (3) C (1) Install (3) Linux (25) Python (10) Raspberry Pi (4)

Thursday, 31 December 2015

How to setup wifi on the Raspberry pi

Setting up wifi on the Raspberry pi on the command line requires a few things.
  1. The ssid i.e. TP-Link
  2. The router password

To get the ssid run :
iwlist wlan0 scan

Then find the ssid out of the data it gives you.
Now we need to login to the Pi.
Once your logged in open up the file /etc/network/interfaces, you will need to be root.
Find the line that says
allow-hotplug wlan0

Add the following lines below it
iface wlan0 inet dhcp
        wpa-ssid "YOURSSID"
        wpa-psk "YOURPASSWORD"

Now reboot your Pi and you should be connected to the wifi.

Wednesday, 23 December 2015

How to get the ASCII values of a string in python

ASCII values are the codes that correspond to printable characters. In total there are 255 but only 127 of them are commonly used.You can look at the ASCII table here
You can also run man ascii to get the ASCII table.
Note: All of the code needs to be run in the python3 console
To get a value of a character in python run:
ord('a')


This should give you the result of 97.
To get the character of a ASCII value in python run:
chr(97)


This should give you the result of 'a'

These built in functions only take 1 argument so if we want to get the ASCII representation of a string then a for loop needs to be implemented.
This would look something like this:
word = input("Please enter a word: ")
for char in word:
        print(ord(char))
 
If we run this with the word hello then we should get the result:
104
101
108
108
111

To store these values in a array this would be implemented by adding the following code.
word = input("Please enter a word: ")
char_array = []
for char in word:
        char_array.append(ord(char))
print(char_array)

If we run this code with the word hello we should get the result:
[104, 101, 108, 108, 111]