[RPi]MCP3008 vs MCP3208

라즈베리파이의 GPIO에는 아날로그 신호를 처리하는 것이 없다. 그래서 아날로그 신호를 내보내는 대부분의 센서를 처리하기 위해서는 ADC(analog-to-digital converter)가 필요하다. ADC 중에는 MCP3008와 MCP3208 등이 있다. 라즈베리파이와 ADC 간의 통신은 SPI를 이용한다.

MCP3008, MCP3004, MCP3208, MCP3204

다음 웹페이지에는 MCP3008, MCP3004, MCP3208, MCP3204 에 대한 데이터시트에 가까운 정보를 제공하고 있다.

Raspberry PI – Adding analogue inputs using MCP3008, MCP3004, MCP3208, MCP3204

그리고 여기는 spidev 라이브러리를 이용하였다. ADC에서 읽은 값이 해상도가 10비트이면 0~1023, 12비트이면 0~4095라는 것을 알 수 있다.

spidev 라이브러리를 이용하여 https://kalten.tistory.com/46 처럼, 통신 여부를 검토하였더니 잘 작동하지 않아서 RPi.GPIO 라이브러리를 이용하였다.

MCP3008에서 센서의 신호처리(SPI통신)

다음은 신호처리를 위해 작성한 파이썬 코드이다. RPi.GPIO 라이브러리를 이용하였다.

import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
 
# MCP3008 칩으로부터 SPI 신호를 읽는다. 8개 센서를 둘 수 있다.(adcnum은 0번부터 7번까지)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
        if ((adcnum > 7) or (adcnum < 0)):
                return -1
        GPIO.output(cspin, True)      # CS핀을 high로 만든다.
 
        GPIO.output(clockpin, False)  # clock핀을 low로 만든다. 
        GPIO.output(cspin, False)     # CS핀을 low로 만든다.
 
        commandout = adcnum
        commandout |= 0x18  # start bit + single-ended bit
        commandout <<= 3    # we only need to send 5 bits here
        for i in range(5):
                if (commandout & 0x80):
                        GPIO.output(mosipin, True)
                else:
                        GPIO.output(mosipin, False)
                commandout <<= 1
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)
 
        adcout = 0
        # MCP3008은 10비트의 해상도를 갖고 있다.
        # MCP3008에서 총 12비트을 읽는다. (=one empty bit, one null bit and 10 ADC bits)
        for i in range(12):
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)
                adcout <<= 1
                if (GPIO.input(misopin)):
                        adcout |= 0x1
 
        GPIO.output(cspin, True)
         
        adcout >>= 1       # first bit is 'null' so drop it
        return adcout      # adcout는 0부터 1023까지 값을 갖는다.
#end of def

MCP3208에서 센서의 신호처리

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

# MCP3208 칩으로부터 SPI 신호를 읽는다. 8개 센서를 둘 수 있다.(adcnum은 0번부터 7번까지)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
        if ((adcnum > 7) or (adcnum < 0)):
                return -1
        GPIO.output(cspin, True)      # CS핀을 high로 만든다.
        GPIO.output(clockpin, False)  # clock핀을 low로 만든다. 시작한다.
        GPIO.output(cspin, False)     # CS핀을 low로 만든다.
        commandout = adcnum
        commandout |= 0x18  # start bit + single-ended bit
        commandout <<= 3    # we only need to send 5 bits here
        for i in range(5):
                if (commandout & 0x80):
                        GPIO.output(mosipin, True)
                else:
                        GPIO.output(mosipin, False)
                commandout <<= 1
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)
        adcout = 0
        # MCP3208은 12비트의 해상도를 갖고 있다.
        # MCP3208에서 총 14비트을 읽는다. (=one empty bit, one null bit and 12 ADC bits)
        for i in range(14):
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)
                adcout <<= 1
                if (GPIO.input(misopin)):
                        adcout |= 0x1
        GPIO.output(cspin, True)
        
        adcout <<= 1       # first bit is 'null' so drop it
        return adcout      # adcout는 0부터 4095까지 값을 갖는다.
#end of def

SPI at Rasberry Pi GPIO Pinout

SPI통신을 위한 라즈베리 파이의 GPIO 핀 배치는 다음과 같다.

SPI – Serial Peripheral Interface at Raspberry Pi

참고문헌

https://github.com/RaresPlescan/daisypi/blob/master/sense/mcp3208/adc_3.py

[rpi]심장 박동 측정

라즈베리파이로 심장 박동을 측정하려 한다.

준비물로는 라즈베리파이, 심장박동 센서( Pulsesensor.com ), ADC (MCP3208)가 필요하다. 심장박동 센서가 아날로그 신호를 내기에 이 신호를 디지털로 바꿔주는 ADC가 있어야 한다.

[통신] 파이와 ADC 간의 통신

라즈베리파이와 ADC 간의 통신은 SPI를 이용한다.

[참고자료]

Building a MicroPython heart rate monitor
Finding the beat in HR sensor data

Heart rate (HR) sensors

[rpi]Windows 10 IoT Core 개발환경 만들기

라즈베리파이3에 WINDOWS 10 IOT CORE 설치

라즈베리파이3 WINDOWS 10 IOT CORE 개발 환경 구축

여기서, 개발 PC를 “개발자 모드”로 변경한다는 것은 원격접속 기능을 사용할 수 있게 한다.

개발 환경 구축하기

WINDOWS 10 IOT CORE에 POWERSHELL로 연결하기

Enter-PSSession-ComputerName192.168.1.202 -Credential192.168.1.202\Administrator
PowerShell로 연결하기

WINDOWS 10 IOT CORE에 SSH로 연결하기

Putty 접속할 때, SSH2_MSG_UNIMPLEMENTED packet error가 발생하면, To solve the issue, open the configuration for the connection and navigate to SSH -> Kex. In the “Algorithm selection policy”, move the “Diffie-Hellman group 14” entry to the first position in the list. (SSH2_MSG_UNIMPLEMENTED packet error with PuTTY and RHEL 7.2 를 참조)한다.

SSH 접속을 위한 PuTTY의 설정 화면

WINDOWS 10 IOT CORE를 위한 VISUAL STUDIO 설정

[rpi]Raspberry Pi Projects

https://pimylifeup.com/category/projects/server/

https://www.networkworld.com/article/3176091/10-killer-raspberry-pi-projects-collection-1.html

https://opensource.com/article/17/4/5-projects-raspberry-pi-home

Digital Signage w/ RPi

[문제]

학과 홍보용 TV에 홍보 슬라이드를 계속해서 보여주고 싶다.

[해법]

0.관련 topic 검색
https://www.raspberrypi.org/forums/viewtopic.php?t=187214
https://www.raspberrypi.org/forums/viewtopic.php?t=90754

1.Screenly
https://www.screenly.io/ose/

2.Pi Presents
https://github.com/KenT2/pipresents-next