Author: nopnop2002

python-periphery and 2G-IOT

[Copy link]

10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
 Author| Published in 2017-9-9 18:17:13 | Show all floors
Edited by nopnop2002 at 2017-9-10 22:08
surfero75 replied at 2017-9-9 15:14
Is there a way for work witch DHT22 sensor?

NO

DHT11/22 needs high-speed digital input.
This library is very slow.
DHT11/22 isn't suitable for Linux.

6

threads

70

posts

370

credits

Intermediate member

Rank: 3Rank: 3

credits
370
Published in 2017-9-12 06:05:09 | Show all floors
Thanks,
A question: how can i show IP address by lcd1602?

10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
 Author| Published in 2017-9-12 18:02:31 | Show all floors
Edited by nopnop2002 at 2017-9-12 18:06
surfero75 replied at 2017-9-12 06:05
A question: how can i show IP address by lcd1602?

YES

--- lcd2.py ---

  1. #!/usr/bin/python
  2. #-*- encoding: utf-8 -*-
  3. #import
  4. from periphery import GPIO
  5. import time
  6. import sys

  7. # Define GPIO to LCD mapping
  8. GPIO.LCD_RS = GPIO(101, "out")
  9. GPIO.LCD_E  = GPIO(121, "out")
  10. GPIO.LCD_D4 = GPIO(122, "out")
  11. GPIO.LCD_D5 = GPIO(123, "out")
  12. GPIO.LCD_D6 = GPIO(124, "out")
  13. GPIO.LCD_D7 = GPIO(125, "out")

  14. # Define some device constants
  15. LCD_WIDTH = 16    # Maximum characters per line
  16. LCD_CHR = True
  17. LCD_CMD = False

  18. LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
  19. LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line

  20. # Timing constants
  21. E_PULSE = 0.0005
  22. E_DELAY = 0.0005

  23. def main(message):
  24.   # Main program block
  25. #  GPIO_setwarnings(False)
  26. #  GPIO_setmode(GPIO_BCM)       # Use BCM GPIO numbers
  27. #  GPIO_setup(LCD_E, GPIO_OUT)  # E
  28. #  GPIO_setup(LCD_RS, GPIO_OUT) # RS
  29. #  GPIO_setup(LCD_D4, GPIO_OUT) # DB4
  30. #  GPIO_setup(LCD_D5, GPIO_OUT) # DB5
  31. #  GPIO_setup(LCD_D6, GPIO_OUT) # DB6
  32. #  GPIO_setup(LCD_D7, GPIO_OUT) # DB7

  33.   # Initialise display
  34.   lcd_init()

  35.   while True:

  36.     # Send some test
  37.     lcd_string("OrangePi 2G-IOT",LCD_LINE_1)
  38.     lcd_string("16x2 LCD Test",LCD_LINE_2)

  39.     time.sleep(3) # 3 second delay

  40.     # Send some text
  41.     lcd_string(message[0],LCD_LINE_1)
  42.     lcd_string("",LCD_LINE_2)
  43.     if (len(message) == 2):
  44.       lcd_string(message[1],LCD_LINE_2)

  45.     time.sleep(3) # 3 second delay

  46. def lcd_init():
  47.   # Initialise display
  48.   lcd_byte(0x33,LCD_CMD) # 110011 Initialise
  49.   lcd_byte(0x32,LCD_CMD) # 110010 Initialise
  50.   lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
  51.   lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
  52.   lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
  53.   lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  54.   time.sleep(E_DELAY)

  55. def lcd_byte(bits, mode):
  56.   # Send byte to data pins
  57.   # bits = data
  58.   # mode = True  for character
  59.   #        False for command

  60.   GPIO.LCD_RS.write(mode) # RS

  61.   # High bits
  62.   GPIO.LCD_D4.write(False)
  63.   GPIO.LCD_D5.write(False)
  64.   GPIO.LCD_D6.write(False)
  65.   GPIO.LCD_D7.write(False)
  66.   if bits&0x10==0x10:
  67.     GPIO.LCD_D4.write(True)
  68.   if bits&0x20==0x20:
  69.     GPIO.LCD_D5.write(True)
  70.   if bits&0x40==0x40:
  71.     GPIO.LCD_D6.write(True)
  72.   if bits&0x80==0x80:
  73.     GPIO.LCD_D7.write(True)

  74.   # Toggle 'Enable' pin
  75.   lcd_toggle_enable()

  76.   # Low bits
  77.   GPIO.LCD_D4.write(False)
  78.   GPIO.LCD_D5.write(False)
  79.   GPIO.LCD_D6.write(False)
  80.   GPIO.LCD_D7.write(False)
  81.   if bits&0x01==0x01:
  82.     GPIO.LCD_D4.write(True)
  83.   if bits&0x02==0x02:
  84.     GPIO.LCD_D5.write(True)
  85.   if bits&0x04==0x04:
  86.     GPIO.LCD_D6.write(True)
  87.   if bits&0x08==0x08:
  88.     GPIO.LCD_D7.write(True)

  89.   # Toggle 'Enable' pin
  90.   lcd_toggle_enable()

  91. def lcd_toggle_enable():
  92.   # Toggle enable
  93.   time.sleep(E_DELAY)
  94.   GPIO.LCD_E.write(True)
  95.   time.sleep(E_PULSE)
  96.   GPIO.LCD_E.write(False)
  97.   time.sleep(E_DELAY)

  98. def lcd_string(message,line):
  99.   # Send string to display

  100.   message = message.ljust(LCD_WIDTH," ")

  101.   lcd_byte(line, LCD_CMD)

  102.   for i in range(LCD_WIDTH):
  103.     lcd_byte(ord(message[i]),LCD_CHR)

  104. if __name__ == '__main__':

  105.   argv = sys.argv
  106.   argc = len(argv)
  107.   if (argc == 1):
  108.     print 'Usage: python %s line1_message [line2_message]' % argv[0]
  109.     quit()

  110.   message = []
  111.   message.append(argv[1])
  112.   if (argc == 3):
  113.     message.append(argv[2])
  114. #  print message

  115.   try:
  116.     main(message)
  117.   except KeyboardInterrupt:
  118.     pass
  119.   finally:
  120.     lcd_byte(0x01, LCD_CMD)
  121.     lcd_string("Goodbye!",LCD_LINE_1)
  122. #    GPIO_cleanup()
Copy code

--- lcd2.sh ---

  1. #!/bin/bash
  2. set -x
  3. ipaddr=`ifconfig wlan0 |grep "inet addr" |awk {'print $2'} |cut -f2 -d:`
  4. if [ -n "$ipaddr" ]; then
  5.    sudo python ./lcd2.py "My IP" $ipaddr
  6. fi
Copy code
chmod 777 lcd2.sh
./lcd2.sh

6

threads

70

posts

370

credits

Intermediate member

Rank: 3Rank: 3

credits
370
Published in 2017-9-12 19:21:21 | Show all floors
Could the script be worth to display any command in the shell? for example ram state, cpu, disk and mp3 player, etc ...?
Thank you very much for your contribution

10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
 Author| Published in 2017-9-12 21:52:36 | Show all floors
surfero75 replied at 2017-9-12 19:21
Could the script be worth to display any command in the shell? for example ram state, cpu, disk and  ...

YES
Try everything.

0

threads

11

posts

140

credits

Registered member

Rank: 2

credits
140
Published in 2017-9-15 17:27:10 | Show all floors
i use i2cdetect -y 0 but i can't detect any device on i2c bus 0
my hardware connection is right, and i already test with arduino and it can detect the address
but when i use 2g iot i can't detect my device, how to detect i2c device ??is there something i miss?

10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
 Author| Published in 2017-9-15 18:27:16 | Show all floors
Edited by nopnop2002 at 2017-9-15 18:36

@jhonoryza
Maybe your connection is right.
i2cdetect in 2g-iot can't be trusted.
I don't trust at all.


3

threads

62

posts

950

credits

Senior member

Rank: 4

credits
950
Published in 2017-11-6 17:31:11 | Show all floors
Are you tested SPI on this board? I confirm that I2C and UART work but I cannot found any spidev

10

threads

218

posts

2040

credits

Gold member

Rank: 6Rank: 6

credits
2040
 Author| Published in 2017-11-6 22:38:05 | Show all floors
Edited by nopnop2002 at 2017-11-6 22:43

No.
I cannot found any spidev.

orangepi@OrangePi:~$ ls /dev/spi*
ls: cannot access '/dev/spi*': No such file or directory
orangepi@OrangePi:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

3

threads

62

posts

950

credits

Senior member

Rank: 4

credits
950
Published in 2017-11-7 00:35:36 | Show all floors
nopnop2002 replied at 2017-11-6 22:38
No.
I cannot found any spidev.

Thanks for answer. then we only can wait
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list