MenuBar

Arduinoの firmware と Android のアプリ

Android + Arduino Mega ADK から Raspberry Pi Zero + Raspberry Pi Pico へ移行中

Raspberry Pi Zero

Raspberry Pi Pico (Arduiono IDE)

Raspberry Pi Zero + Raspberry Pi Pico + GPS ... 場所依存表示可能バージョン

Hardware

Raspberry Pi Zero 2 <-> GPIO i2c 400khz-> Raspberry Pi Pico (arduino)
                    <-> GPIO UART <-> Adafruit Ultimate GPS

i2c 400khz

gps

  • /etc/default/gpsd
    ٤Ƴ٤Ĥ
      1
      2
      3
      4
      5
      6
      7
      8
      9
    
     
     
     
     
     
     
     
     
     
    
    # Devices gpsd should collect to at boot time.
    # They need to be read/writeable, either by user gpsd or the group dialout.
    #DEVICES=""
    DEVICES="/dev/serial0"
    # Other options you want to pass to gpsd
    #GPSD_OPTIONS=""
    GPSD_OPTIONS="-F /var/run/gpsd.sock"
    # Automatically hot add/remove USB GPS devices via gpsdctl
    #USBAUTO="true"

Software

  • systemd, start sh
    • /etc/systemd/system/wiki_bot.service
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
       11
       12
      
      [Unit]
      Description=wiki_bot
      After=network.target
       
      [Service]
      User=pi
      Type=simple
      WorkingDirectory=/home/pi/python
      ExecStart=/home/pi/python/start_wiki_bot.sh
       
      [Install]
      WantedBy=multi-user.target
    • /home/pi/python/start_wiki_bot.sh
        1
        2
        3
        4
        5
        6
        7
      
      #!/usr/bin/bash
      sleep 120
      xhost +
      export DISPLAY=:0.0
      cd /home/pi/python
      source testpip/bin/activate
      python3 wiki_bot_08.py -s
    • /home/pi/python/start_wiki_bot.sh ... LINE Bot 接続版
        1
        2
        3
        4
        5
        6
        7
        8
        9
      
      #!/usr/bin/bash
      sleep 120
      xhost +
      export DISPLAY=:0.0
      cd /home/pi/python/line-bot
      ngrok http --domain=<ngrok static domain> 3000 &
      cd /home/pi/python
      source testpip/bin/activate
      python3 wiki_bot_09.py -s
  • bot
    • wiki_bot_ex08.py
    • gps関連追加部分
      ٤Ƴ٤Ĥ
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
       11
       12
       13
       14
       15
       16
       17
       18
       19
       20
       21
       22
       23
       24
       25
       26
       27
       28
       29
       30
       31
       32
       33
       34
       35
       36
       37
       38
       39
       40
       41
       42
       43
       44
       45
       46
       47
       48
       49
       50
       51
       52
       53
       54
       55
       56
       57
       58
       59
       60
       61
       62
       63
       64
       65
       66
       67
       68
       69
       70
       71
       72
       73
       74
       75
       76
       77
       78
       79
       80
       81
       82
       83
      
       
       
       
       
       
       
       
       
       
       
       
       
      -
      |
      |
      !
       
      -
      !
       
       
       
      -
      !
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
      -
      |
      |
      |
      |
      !
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
      
      from gps3 import gps3
      import math
       
      class pico_wiki_bot:
       
          gps_time="n/a_"
          gps_lat="n/a_"
          gps_lon="n/a_"
          gps_alt="n/a_"
          gps_speed="n/a_"
       
          def __init__(self):
              #
              # gps thread
              #
              self.gps_thread=threading.Thread(target=self.start_gps)
              print('new thread, start gps_thread')
              #self.start_script()
              print('self.gps_thread.start()')
              self.gps_thread.start()
              print('script_started.')
       
              #
          def start_gps(self):
              print('start_gps')
              try:
                  gps_socket = gps3.GPSDSocket()
                  data_stream = gps3.DataStream()
                  gps_socket.connect()
                  gps_socket.watch()
       
                  for new_data in gps_socket:
                      if new_data:
                          data_stream.unpack(new_data)
                          self.gps_time=data_stream.TPV['time']
                          self.gps_lat=data_stream.TPV['lat']
                          self.gps_lon=data_stream.TPV['lon']
                          self.gps_alt=data_stream.TPV['alt']
                          self.gps_speed=data_stream.TPV['speed']
                          #print('time : ', self.gps_time)
                          #print('lat : ', self.gps_lat)
                          #print('lon : ', self.gps_lon)
                          #print('alt : ', self.gps_alt)
                          #print('speed : ', self.gps_speed)
              except Exception as e:
                  import traceback
                  traceback.print_exc()
                  print(e)
                  print('error')
                  return
       
          def geo_distance(self,lat_1,lon_1, lat_2, lon_2): #degree
              if type(lat_1) is str:
                  return "n/a"
              if type(lon_1) is str:
                  return "n/a"
              if type(lat_2) is str:
                  return "n/a"
              if type(lon_2) is str:
                  return "n/a"
              pole_radius = 6356752.314245     # 極半径
              equator_radius = 6378137.0       # 赤道半径
       
              da1r=lat_1*3.1415926535/180.0
              do1r=lon_1*3.1415926535/180.0
              da2r=lat_2*3.1415926535/180.0
              do2r=lon_2*3.1415926535/180.0
       
              lat_difference = da1r - da2r     # 緯度差
              lon_difference = do1r - do2r     # 経度差
              lat_average = (da1r + da2r) / 2.0   # 平均緯度
       
              e2 = (pow(equator_radius, 2) - pow(pole_radius, 2)) / pow(equator_radius, 2)  # 第一離心率^2
       
              w = math.sqrt(1- e2 * pow(math.sin(lat_average), 2))
              m = equator_radius * (1 - e2) / pow(w, 3)     # 子午線曲率半径
       
              n = equator_radius / w                             # 卯酉線曲半径
       
              distance = math.sqrt(pow(m * lat_difference, 2) + pow(n * lon_difference * math.cos(lat_average), 2)) # 距離計測
              print('distance={:f}'.format(distance))
              return distance
       
      
  • external

Raspberry Pi Pico (Arduiono IDE)

wiki page

BDF東雲明朝16x16 フォント


Counter: 967, today: 2, yesterday: 2

添付ファイル: fileShinonomeMin_16.pdb 350件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2025-07-22 (火) 21:31:30