User Tools

Site Tools


hardware:raspberry_pi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hardware:raspberry_pi [2021/03/31 03:33]
nanodano [I2C stuff]
hardware:raspberry_pi [2021/03/31 17:40] (current)
nanodano
Line 86: Line 86:
 </code> </code>
  
-===== Configure static IP address for eth0 =====+===== Networking ===== 
 + 
 +==== Configure static IP address for eth0 ====
  
 It should use DHCP by default, but if you want to specify an IP Address you can. It should use DHCP by default, but if you want to specify an IP Address you can.
Line 99: Line 101:
 </code> </code>
  
-===== Manually configure wpa_supplicant for WiFi =====+==== Manually configure wpa_supplicant for WiFi ====
  
 <code bash> <code bash>
Line 124: Line 126:
 </code> </code>
  
-===== Expose local port via remote server =====+==== Expose local port via remote server ====
  
 You can take a service running locally, and use a remote VPS to be a proxy and allow connectivity from the internet. You can take a service running locally, and use a remote VPS to be a proxy and allow connectivity from the internet.
Line 312: Line 314:
  
  
-==== I2C stuff ====+===== I2C stuff =====
  
 Turn on i2c using ''raspi-config'' under Interface options. Reboot after enabling. This will create a device like ''/dev/i2c-1''. Turn on i2c using ''raspi-config'' under Interface options. Reboot after enabling. This will create a device like ''/dev/i2c-1''.
  
-Install ''i2c-utils'' to get tools like '/usr/sbin/i2cdetect''.+Install ''i2c-utils'' to get tools like ''/usr/sbin/i2cdetect''.
  
 <code bash> <code bash>
Line 323: Line 325:
 sudo i2cdetect 1  # they're in sbin, so need sudo sudo i2cdetect 1  # they're in sbin, so need sudo
 sudo i2cdump --help sudo i2cdump --help
 +</code>
 +
 +==== I2C C library ====
 +
 +<code c test_i2c.cpp>
 +/* test_i2c.cpp
 + * Compile with:
 +   g++ test_i2c.cpp -lwiringPi
 + */
 +#include <iostream>
 +#include <errno.h>
 +#include <wiringPiI2C.h>
 +
 +int main() {
 +
 +   /* Provide the i2c address from `sudo i2cdetect` */
 +   int file_handle = wiringPiI2CSetup(0x60);
 +
 +   int result = wiringPiI2CWrite(file_handle, 0x40, 0xDEAD );
 +   if (result == -1) {
 +      std::cout << "Error #" << errno << std::endl;
 +   } else {
 +       std::cout << "Result: " << result << std::endl;
 +   }
 +
 +   return 0;
 +}
 +</code>
 +
 +==== I2C Python Library ====
 +
 +Install the [[https://packages.debian.org/buster/python3-smbus|Python3 smbus]] library using ''apt''.
 +
 +<code bash>
 +sudo apt-get install python3-smbus
 +</code>
 +
 +
 +<code python test_i2c.py>
 +# Reference adapted from: https://pypi.org/project/smbus2/
 +from smbus import SMBus
 +
 +DEVICE_ADDRESS = 80
 +
 +bus1 = SMBus(1)
 +data = bus1.read_byte_data(DEVICE_ADDRESS, 0) # From offset 0
 +print(data)
 +bus1.close()
 +
 +with SMBus(1) as bus1:
 +    # Write a byte to device address, offset 0
 +    data = 45
 +    bus1.write_byte_data(DEVICE_ADDRESS, 0, data)
 </code> </code>
  
  
  
hardware/raspberry_pi.1617161637.txt.gz · Last modified: 2021/03/31 03:33 by nanodano