개발자/라즈베리파이4

아쿠아포닉스 ORP 센서 Data 수집 2

지구빵집 2023. 1. 31. 09:45
반응형

 

 

 

여기서는 실제 센서 회로보드를 연결하고 데이터를 수집하는 과정을 보여준다. 어렵지 않으므로 쉽게 따라 할 수 있다. 아래는 ORP 센서를 마이크로 컨트롤러와 연결할 때 참고한다. 센서 인터페이스를 UART와 I2C 모드를 변경할 때 참고할 링크는맨 아래 참고 링크를 보기 바란다.

 

 

 

 

 

Atlas Scientific™ EZO™ 클래스 회로가 I2C 모드인지 확인한다. 라즈베리 파이와 함께 EZO™ 클래스 회로를 사용하려면 먼저 아래 명령어를 사용하여 패키지를 설치해야 한다.

 

$ sudo apt-get install python-smbus  

 

$ sudo apt-get install i2c-tools  

 

다음은 $ sudo raspi-config 명령어를 사용하여 라즈베리파이 보드의 I2C 인터페이스를 사용가능하도록 활성화(인에이블) 해야 한다. 아래 이미지를 참고하여 설정한다. 이미 설정도어 있다면 가볍게 넘어간다.

 

$ sudo raspi-config 

 

 

I2C 인터페이스를 사용가능하도록 활성화
I2C 인터페이스를 사용가능하도록 활성화
I2C 인터페이스를 사용가능하도록 활성화
I2C 인터페이스를 사용가능하도록 활성화
I2C 인터페이스를 사용가능하도록 활성화

 

아래와 같이 회로 연결을 한다. 여기서 4.7k 풀업 저항을 달지 않으면 동작하지 않는다. 

 

 

ORP 센서 회로보드와 라즈베리파이 연결

 

제대로 연결되었는지 i2c 주소를 아래와 같이 확인한다.

 

Atlas Scientific 센서는 모두 다른 i2c 주소를 갖고 있으며, 아래 첨부한 i2c 주소 리스트를 참고한다.

 

 

Atlas Scientific 센서 i2c 주소 리스트

 

$ sudo i2cdetect -y 1

 

프로그램은 연결된 각 I2C 장치에 대한 정보를 알려주고, 아래는  I2C 주소(0x63)가 사용 중임을 나타낸다. 

 

pi@raspberrypi:~/Raspberry-Pi-sample-code $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- 62 -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi:~/Raspberry-Pi-sample-code $

 

연결이 되었다면 다음 프로그램을 실행하여 센서에 연결하고 시험을 진행한다.

 

$ cd ~/Raspberry-Pi-sample-code  

 

$ sudo python i2c.py 를 실행하면 아래와 같이 실행하는 화면을 볼 수 있다. 간단한 사용법과 명령어를 아래에 나타낸다. 

 

pi@raspberrypi:~/Raspberry-Pi-sample-code $ sudo python i2c.py

>> Atlas Scientific I2C sample code
>> Any commands entered are passed to the default target device via I2C except:
  - Help
      brings up this menu
  - List
      lists the available I2C circuits.
      the --> indicates the target device that will receive individual commands
  - xxx:[command]
      sends the command to the device at I2C address xxx
      and sets future communications to that address
      Ex: "102:status" will send the command status to address 102
  - all:[command]
      sends the command to all devices
  - Poll[,x.xx]
      command continuously polls all devices
      the optional argument [,x.xx] lets you set a polling time
      where x.xx is greater than the minimum 1.50 second timeout.
      by default it will poll every 1.50 seconds
>> Pressing ctrl-c will stop the polling

 

list 명령어는 현재 연결된 i2c 센서 리스트를 나타낸다. 다른 i2c 센서와 통신하기 위해서는 i2c 주소와 콜론을 입력한다. 99:

현재 orp 센서의 어드레스가 98이므로 98:l 이나 98:status 명령어로 잘 응답한다.

 

데이터를 얻기 위해 poll 명령어를 입력한다. poll , 뒤에는 데이터를 읽는 간격을 입력할 수 있는데 최소 1.5초이므로 poll, 1.5 로 입력 할 수 있다. 디폴트 값이기도 하다. poll, 3 입력하면 3초마다 값을 볼 수 있다. 현재는 센서를 연결하지 않고 회로보드만 테스트하는 중이라 아래와 같은 결과가 잘 나온다.

 

pi@raspberrypi:~/Raspberry-Pi-sample-code $
pi@raspberrypi:~/Raspberry-Pi-sample-code $ sudo python i2c.py

>> Atlas Scientific I2C sample code
>> Any commands entered are passed to the default target device via I2C except:
  - Help
      brings up this menu
  - List
      lists the available I2C circuits.
      the --> indicates the target device that will receive individual commands
  - xxx:[command]
      sends the command to the device at I2C address xxx
      and sets future communications to that address
      Ex: "102:status" will send the command status to address 102
  - all:[command]
      sends the command to all devices
  - Poll[,x.xx]
      command continuously polls all devices
      the optional argument [,x.xx] lets you set a polling time
      where x.xx is greater than the minimum 1.50 second timeout.
      by default it will poll every 1.50 seconds
>> Pressing ctrl-c will stop the polling

--> ORP 98
>> Enter command: poll, 3
-------press ctrl-c to stop the polling
Success ORP 98: -450.3
-------press ctrl-c to stop the polling
Success ORP 98: -448.6
-------press ctrl-c to stop the polling
Success ORP 98: -448.9
-------press ctrl-c to stop the polling
Success ORP 98: -447.8
-------press ctrl-c to stop the polling
Success ORP 98: -443.9

 

참고

HOW TO CHANGE DATA PROTOCOL OF ATLAS SENSORS 

 

 

 

반응형