Search

'Raspberry Pi'에 해당되는 글 4건

  1. 2017.02.12 Raspberry PI - Speaker pHAT
  2. 2016.12.14 Blueinno2(RFduinoBLE) - Raspberry PI 3 / BLE 연동 (1)
  3. 2016.11.20 Raspberry Pi & Bluetooth LE(nurum) / LED Control (4)
  4. 2016.10.12 Raspberry PI Pixel

Raspberry PI - Speaker pHAT

OS/Raspberry Pi 2017.02.12 19:35 Posted by 파란크리스마스

Speaker pHAT

출처 : https://shop.pimoroni.com/products/speaker-phat
Setting up pHAT DAC
Pi VU Meter ( ALSA Plugin to display a VU meter on various Raspberry Pi add-ons )
Raspberry Pi Zero Streaming Airplay using Speaker pHAT - YouTube

자동 설치

$ curl https://get.pimoroni.com/phatdac | bash

Pi VU Meter 설치

출처 : Pi VU Meter ( ALSA Plugin to display a VU meter on various Raspberry Pi add-ons )

$ git clone https://github.com/pimoroni/pivumeter.git
$ cd pivumeter
$ setup.sh blinkt

수동 설치

$ git clone https://github.com/pimoroni/speaker-phat
Cloning into 'speaker-phat'...
remote: Counting objects: 128, done.
remote: Total 128 (delta 0), reused 0 (delta 0), pack-reused 128
Receiving objects: 100% (128/128), 114.17 KiB | 23.00 KiB/s, done.
Resolving deltas: 100% (39/39), done.
Checking connectivity... done.
$ cd speaker-phat
$ sudo ./setup.sh
 
This script will install everything needed to use
Speaker pHAT
 
--- Warning ---
 
Always be careful when running scripts and commands
copied from the internet. Ensure they are from a
trusted source.
 
Checking for required packages...
Enabling I2C interface...
 
Installing ALSA plugin...
 
Configuring sound output...
 
Adding Device Tree Entry to /boot/config.txt
dtoverlay=i2s-mmap
dtoverlay=hifiberry-dac
 
Commenting out Blacklist entry in
/etc/modprobe.d/raspi-blacklist.conf
 
Disabling default sound driver
 
All done!
 
Enjoy your Speaker pHAT!
 
Some changes made to your system require
your computer to reboot to take effect.
 
Would you like to reboot now? [y/N]
$ sudo shutdown -r now

플레이어 설치

출처 : GUI based MP3 players

$ apt-get install lxmusic


저작자 표시
신고

Blueinno2(RFduinoBLE) - Raspberry PI 3 / BLE 연동

OS/Raspberry Pi 2016.12.14 01:11 Posted by 파란크리스마스

출처 : Raspberry Pi: Control WS2812B (NeoPixels) With Bluetooth LE
Eclipse Kura™ Documentation
The Pi4J Project

Bluetooth 모듈이 내장된 블루이노2로 BLE 송신하고, 라즈베리파이3의 Bluetooth 모듈로 수신 받아 데이터처리 해보았습니다.

블루이노2 코드

#include <RFduinoBLE.h>

int Potent=2;
boolean is_connect;

void setup() {
  // put your setup code here, to run once:
  RFduinoBLE.deviceName = "bluexmas";

  // this is the data we want to appear in the advertisement
  //RFduinoBLE.advertisementData = "My BLE LED";
  
  //RFduinoBLE.advertisementInterval = MILLISECONDS(300);
  //RFduinoBLE.txPowerLevel = -20;  // (-20dbM to +4 dBm)
    
  Serial.begin(9600);  
  Serial.println("Start Test");      // With more than 15 characters thie Start Test keeps happening

  // start the BLE stack
  RFduinoBLE.begin();  
}

void loop() {
  char BPM_lcd[10];
  
  RFduino_ULPDelay(100);  
  // Switch to lower power mode
  //RFduino_ULPDelay(INFINITE);
  //RFduino_ULPDelay( SECONDS(1) ); //sample once per second

  if (is_connect) {
    int sensorValue = analogRead(Potent);
    Serial.println(sensorValue);             // debug value

    //sprintf(BPM_lcd, "%10d", sensorValue);
    //lcd.println(BPM_lcd);     
    
    RFduinoBLE.sendInt(sensorValue);  //sends the char array
  }
}

void RFduinoBLE_onConnect() {
  // Debug message printed to Serial interface
  Serial.println("RFduino connected");
  is_connect = true;
}

void RFduinoBLE_onDisconnect() { 
  // Debug message printed to Serial interface
  Serial.println("RFduino disconnected");
  is_connect = false;
}

void RFduinoBLE_onReceive(char *data, int len) {
  // Debug message printed to Serial interface
  Serial.println("Data received: ");
  for(int i=0;i<len;i++)
    Serial.print(data[i]);
    Serial.println();
    Serial.println(data);
}

Blueinno.java

BLE 관련 코드만 보기 편하게 하기 위해서 모터 제어 관련 코드는 빼고 블루이노2와 통신하는 부분만 공개

package ble.blueinno2;

import java.util.List;
import java.util.Scanner;

import org.eclipse.kura.KuraException;
import org.eclipse.kura.bluetooth.BluetoothDevice;
import org.eclipse.kura.bluetooth.BluetoothGatt;
import org.eclipse.kura.bluetooth.BluetoothGattService;
import org.eclipse.kura.bluetooth.BluetoothLeNotificationListener;
import org.eclipse.kura.bluetooth.BluetoothLeScanListener;
import org.eclipse.kura.linux.bluetooth.util.BluetoothProcess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Blueinno implements BluetoothLeNotificationListener, BluetoothLeScanListener {
	
	private static final Logger logger = LoggerFactory.getLogger(BluetoothProcess.class);

	private BluetoothGatt m_bluetoothGatt;
	private BluetoothDevice m_device;
	private boolean m_connected;

	public Blueinno(BluetoothDevice bluetoothDevice) {
		// m_device = bluetoothDevice;
		m_connected = false;
	}

	public BluetoothDevice getBluetoothDevice() {
		return m_device;
	}

	public void setBluetoothDevice(BluetoothDevice device) {
		m_device = device;
	}

	public boolean isConnected() {
		return m_connected;
	}

	public boolean connect(BluetoothLeNotificationListener listener) throws KuraException {
		m_bluetoothGatt = m_device.getBluetoothGatt();
		logger.info("접속시도");
		boolean connected = m_bluetoothGatt.connect();
		if (connected) {
			m_bluetoothGatt.setBluetoothLeNotificationListener(listener);
			logger.info("리스너등록");
			m_connected = true;
			return true;
		} else {
			// If connect command is not executed, close gatttool
			m_bluetoothGatt.disconnect();
			m_connected = false;
			return false;
		}
	}

	public void disconnect() {
		if (m_bluetoothGatt != null) {
			m_bluetoothGatt.disconnect();
			m_connected = false;
		}
	}

	/*
	 * Discover services
	 */
	public List<BluetoothGattService> discoverServices() {
		return m_bluetoothGatt.getServices();
	}

	@Override
	public void onScanFailed(int errorCode) {
		// TODO Auto-generated method stub
		System.out.println("error = " + errorCode);
	}

	@Override
	public void onScanResults(List<BluetoothDevice> devices) {
		logger.info("onScanResults = " + devices.size());

		for (BluetoothDevice device : devices) {
			logger.info("Found Bluetooth Device " + device.getName() + " [" + device.getAdress() + "]");
		}
		
		System.out.print("ble address > ");
		Scanner scanner = new Scanner(System.in);
		String blc_address = scanner.next();
		
		BluetoothDevice nurum_device = null;
		for (BluetoothDevice device : devices) {
			if (device.getAdress().equals(blc_address)) {
				nurum_device = device;
			}
		}
		
		if (nurum_device != null) {
			//ble_nurum = new Blueinno(nurum_device);
			this.setBluetoothDevice(nurum_device);
			try {
				if (this.connect(this)) {
					System.out.println("ble connect");
					
					Runnable aa = new Runnable() {
						
						@Override
						public void run() {
							while (true) {
								try {
									String sensorValue = m_bluetoothGatt.readCharacteristicValue("0x000e");
									System.out.println(sensorValue);
									
									// 모터제어
									// 생략
								} catch (KuraException e1) {
									e1.printStackTrace();
								}
								try {
									Thread.sleep(100);
								} catch (Exception e) {
									
								}
							}
						}
					};
					
					Thread bb = new Thread(aa);
					bb.start();
				}
			} catch (KuraException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	@Override
	public void onDataReceived(String handle, String value) {
		System.out.println("handle: " + handle + " value: " + value);
	}
}

BlueinnoMain.java

package ble.blueinno2;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.eclipse.kura.linux.bluetooth.le.BluetoothLeScanner;

public class BlueinnoMain {
	
	Logger logger = Logger.getLogger(this.getClass());

	private Blueinno blueinno = null;
	
	public static void main(String[] args) throws Exception {
		BlueinnoMain bletest = new BlueinnoMain();
		bletest.init();
		bletest.startScan();
	}
	
	public void init() {
		Logger.getRootLogger().setLevel(Level.DEBUG);
		logger.info("초기화");
		blueinno = new Blueinno();
	}

	public void startScan() throws InterruptedException {
		BluetoothLeScanner m_bls = new BluetoothLeScanner();
		m_bls.startScan("hci0", blueinno);
		Thread.sleep(10000);
		m_bls.killScan();
	}
}

실행


저작자 표시
신고

Raspberry Pi & Bluetooth LE(nurum) / LED Control

OS/Raspberry Pi 2016.11.20 02:11 Posted by 파란크리스마스

출처 : Eclipse Kura™ Documentation
The Pi4J Project

라즈베리파이2에 BLE 동글이와 BLE 스마트 버튼인 nurum으로 클릭 이벤트를 받아서
GPIO를 이용해서 LED를 컨트롤 해보았습니다.

BleNurum class

package bletest;

import java.util.List;

import org.eclipse.kura.KuraException;
import org.eclipse.kura.bluetooth.BluetoothDevice;
import org.eclipse.kura.bluetooth.BluetoothGatt;
import org.eclipse.kura.bluetooth.BluetoothGattService;
import org.eclipse.kura.bluetooth.BluetoothLeNotificationListener;

public class BleNurum {

	private BluetoothGatt m_bluetoothGatt;
	private BluetoothDevice m_device;
	private boolean m_connected;

	public BleNurum(BluetoothDevice bluetoothDevice) {
		m_device = bluetoothDevice;
		m_connected = false;
	}

	public BluetoothDevice getBluetoothDevice() {
		return m_device;
	}

	public void setBluetoothDevice(BluetoothDevice device) {
		m_device = device;
	}

	public boolean isConnected() {
		return m_connected;
	}

	public boolean connect(BluetoothLeNotificationListener listener) throws KuraException {
		m_bluetoothGatt = m_device.getBluetoothGatt();
		boolean connected = m_bluetoothGatt.connect();
		if (connected) {
			m_bluetoothGatt.setBluetoothLeNotificationListener(listener);
			m_connected = true;
			return true;
		} else {
			// If connect command is not executed, close gatttool
			m_bluetoothGatt.disconnect();
			m_connected = false;
			return false;
		}
	}

	public void disconnect() {
		if (m_bluetoothGatt != null) {
			m_bluetoothGatt.disconnect();
			m_connected = false;
		}
	}

	/*
	 * Discover services
	 */
	public List<BluetoothGattService> discoverServices() {
		return m_bluetoothGatt.getServices();
	}
}

BleTestMain class

package bletest;

import java.nio.ByteBuffer;
import java.util.List;
import java.util.Scanner;

import org.eclipse.kura.KuraException;
import org.eclipse.kura.bluetooth.BluetoothDevice;
import org.eclipse.kura.bluetooth.BluetoothLeNotificationListener;
import org.eclipse.kura.bluetooth.BluetoothLeScanListener;
import org.eclipse.kura.linux.bluetooth.le.BluetoothLeScanner;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class BleTestMain implements BluetoothLeScanListener, BluetoothLeNotificationListener {
	
	private BleNurum ble_nurum = null;
	private GpioController gpio = null;
	private GpioPinDigitalOutput led_01 = null;
	private GpioPinDigitalOutput led_02 = null;
	
	public static void main(String[] args) throws Exception {
		BleTestMain bletest = new BleTestMain();
		bletest.init();
		bletest.startScan();
	}
	
	public void init() {
		// create gpio controller
		gpio = GpioFactory.getInstance();
		led_01 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08, "Red LED", PinState.HIGH);
		led_02 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_09, "Blue LED", PinState.HIGH);
		// set shutdown state for this pin
		led_01.setShutdownOptions(true, PinState.LOW);
		led_02.setShutdownOptions(true, PinState.LOW);
		led_01.low();
		led_02.low();
	}

	public void startScan() throws InterruptedException {
		BluetoothLeScanner m_bls = new BluetoothLeScanner();
		m_bls.startScan("hci0", this);

		Thread.sleep(3000);

		m_bls.killScan();
	}

	@Override
	public void onScanFailed(int errorCode) {
		// TODO Auto-generated method stub
		System.out.println("error = " + errorCode);
	}

	@Override
	public void onScanResults(List<BluetoothDevice> devices) {
		System.out.println("onScanResults = " + devices.size());

		for (BluetoothDevice device : devices) {
			System.out.println("Found Bluetooth Device " + device.getName() + " [" + device.getAdress() + "]");
		}
		
		System.out.print("ble address > ");
		Scanner scanner = new Scanner(System.in);
		String blc_address = scanner.next();
		
		BluetoothDevice nurum_device = null;
		for (BluetoothDevice device : devices) {
			if (device.getAdress().equals(blc_address)) {
				nurum_device = device;
			}
		}
		
		if (nurum_device != null) {
			ble_nurum = new BleNurum(nurum_device);
			try {
				if (ble_nurum.connect(this)) {
					System.out.println("ble connect");
				}
			} catch (KuraException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static byte[] decode(String hex) {

		String[] list = hex.split("(?<=\\G.{2})");
		ByteBuffer buffer = ByteBuffer.allocate(list.length);
		System.out.println(list.length);
		for (String str : list)
			buffer.put(Byte.parseByte(str, 16));

		return buffer.array();

	}

	@Override
	public void onDataReceived(String handle, String value) {
		String val = new String( decode(value.replaceAll("\\p{Z}", "")) );
		
		System.out.println("handle: " + handle + " value: " + value + " / " + val);
		
		if (val.equals("!1")) {
			led_01.toggle();
		}
		
		if (val.equals("!2")) {
			led_02.toggle();
		}
		
		if (val.equals("!3")) {
			led_01.low();
			led_02.low();
		}		
		
		if (val.equals("!H")) {
			ble_nurum.disconnect();
			gpio.shutdown();
			System.exit(1);
		}
	}
}

실행

$ sudo java -cp .:pi4j-core.jar:org.apache.commons.io_2.4.0.jar:org.eclipse.equinox.io_1.0.400.v20120522-2049.jar:org.eclipse.osgi_3.8.1.v20120830-144521.jar:org.eclipse.osgi.services_3.3.100.v20120522-1822.jar:org.eclipse.osgi.util_3.2.300.v20120522-1822.jar:org.eclipse.soda.dk.comm_1.2.1.jar:slf4j.api_1.6.4.jar:slf4j.jdk14_1.6.4.jar:slf4j.log4j12_1.6.0.jar:usb4java-javax_1.0.0.jar bletest.BleTestMain

저작자 표시
신고

Raspberry PI Pixel

OS/Raspberry Pi 2016.10.12 14:27 Posted by 파란크리스마스

마우스 반응 속도 개선

출처 : 라즈베리파이 무선마우스 속도 감도 문제 해결

cmdline.txt 파일의 첫줄에 usbhid.mousepoll=0 추가 / 디폴트가 8로 너무 빠르다 싶으면 숫자를 올려준다.

$ sudo vi /boot/cmdline.txt

최신 버전으로 업데이트

$ sudo apt-get update
$ sudo apt-get upgrade

XRDP 사용

출처 : Introducing PIXEL - Raspberry Pi
Raspberry Pi Adds Beautiful "Pixel" Desktop Environment To ...

최신 라즈베리파이OS인 PIXEL의 경우 기본적으로 VNC서버가 설치되어 있으므로, XRDP를 사용하실 경우 VNC 서버를 삭제 해야됩니다.

VNC서버 삭제 (RealVNC가 설치되어 있는 경우 사용)

$ sudo apt-get autoremove --purge realvnc
$ sudo apt-get purge realvnc-vnc-server

XRDP 설치

$ sudo apt-get install xrdp

라즈베리파이 펌웨어 업데이트

출처 : 라즈베리파이 펌웨어 업데이트 하기 (firmware update on the R-Pi)

$ sudo apt-get install ca-certificates
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ca-certificates is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ sudo apt-get install git-core
Reading package lists... Done
Building dependency tree       
Reading state information... Done
git-core is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

리눅스 정보

$ uname -a
Linux raspberrypi 4.4.21-v7+ #911 SMP Thu Sep 15 14:22:38 BST 2016 armv7l GNU/Linux

HC-06 UART 설정

출처 : Raspberry Pi 3 UART baud rate workaround
RaspberryPi3でシリアル通信を行う - Qiita
Brian Dorey.com | Raspberry Pi 3 UART Boot Overlay Part Two

환경파일 /boot/config.txt 수정

내용 추가 dtoverlay=pi3-miniuart-bt, enable_uart=1, core_freq=25

$ sudo vi /boot/config.txt

변경후

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi
dtoverlay=pi3-miniuart-bt
enable_uart=1
core_freq=250

해상도 변경

출처 : studymake.blogspot.kr: [00076] 라즈베리파이 해상도 변경하는 방법

$ sudo vi /boot/config.txt

아래 해당 부분의 주석 제거

hdmi_force_hotplug = 1
hdmi_group = 2
hdmi_mode = 16 # 16 = 1024x768   60 Hz
hdmi_drive = 1

한글 폰트 설치

$ sudo apt-get install ttf-unfonts-core

한글 입력기 설치

$ sudo apt-get install fcitx-hangul

node.js 설치

출처 : Installing Node.js v4.0.0 on a Raspberry Pi (All Models) - Blog - Wia

$ wget https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-armv7l.tar.gz
$ tar -xvf node-v4.0.0-linux-armv7l.tar.gz
$ cd node-v4.0.0-linux-armv7l
$ sudo cp -R * /usr/local/

node.js 설치 확인

$ command node -v
v4.0.0

스마트미러 설치

출처 : Smart Mirror 스마트 미러 만들기- 4 Smart Mirror GitHub 다운 및 실행

$ mkdir test-smart-mirror
$ cd test-smart-mirror
$ git clone https://github.com/evancohen/smart-mirror.git
Cloning into 'smart-mirror'...
remote: Counting objects: 3760, done.
remote: Compressing objects: 100% (107/107), done.
remote: Total 3760 (delta 56), reused 0 (delta 0), pack-reused 3653
Receiving objects: 100% (3760/3760), 10.85 MiB | 2.09 MiB/s, done.
Resolving deltas: 100% (2072/2072), done.
Checking connectivity... done.
$ cd smart-mirror
$ cp config.example.js config.js
$ npm install

스마트미러 실행

$ npm start

스마트미러 실행 화면


$ lsusb
Bus 001 Device 004: ID 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
Bus 001 Device 006: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0


저작자 표시
신고


 

티스토리 툴바