In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the method of Python iota hardware integration". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Components and devices
First, let's take a look at the components needed for the project. You should be able to sell these components in most electronic components stores or on Taobao for no more than 350 yuan.
Raspberry pie
The brain of the project is raspberry pie. Raspberry pie will run to monitor the balance of IOTA addresses and process signals on the general input-output (GIO) pin of raspberry pie:
Relay
Relays are used to switch the switches of circuits and equipment (here we are LED). To simplify the circuit, we will use a relay module that contains all the necessary components, pins and connectors. Note that you can also purchase multi-channel relay modules, as long as each channel can be turned on and off separately.
Bread board
The bread board is used to connect the circuits without welding, which makes the assembly process easier.
Light emitting diode
The LED lights up when it is powered, and we use it to represent the physical equipment in the project (such as refrigerators).
300 ohms resistance
Resistors are used to limit the current passing through the LED. Without resistance, LED and raspberry pie may be damaged by too much current. The resistance to be used depends on your LED and the voltage of the circuit. In my demonstration, a 9V battery was used, so a resistance of 330 ohms should be fine.
Battery
The battery provides power for the circuit. I used a 9v battery in my demo.
Connecting line
Of course, we also need some wires to connect the parts:
Two-dimensional code
If you want to use your mobile IOTA wallet to pay for the use of LED (refrigerator, washing machine.), a printed QR code of the IOTA collection address will be convenient. When you use IOTA wallet to generate an address, you will find a QR code. Or look up the QR code of an existing address on the THETANGLE website.
Assembling circuit
Now let's take a look at the assembled circuits:
The pins of raspberry pie are as follows:
Refer to the following instructions to connect the pins:
Raspberry pie pin 2 (5v) is connected to the VCC pin of the relay module
Raspberry pie pin 6 (ground) connected to the GND pin of the relay module
Raspberry pie pin 12 (GPIO18) is connected to the IN pin of the relay module
The COM terminal of the relay module is connected to the positive pole of the battery
The NO terminal of the relay module is connected to the positive pole of the LED through a resistor.
The negative electrode of the battery is connected to the negative electrode of the LED.
Required software and libraries
Before we start writing Python code, we need to make sure that the required software and libraries are installed on the raspberry pie.
First, we need to install an operating system on the raspberry pie. Any LInux distribution supported by the raspberry pie should work. In my demo, I used the Raspbian distribution because it already comes with Python and several Python editors.
Finally, we need to install the PyIOTA API library, which allows us to use Python to access IOTA tangle.
Python code
Now start writing code:
# Imports some Python Date/Time functionsimport timeimport datetime# Imports GPIO libraryimport RPi.GPIO as GPIO# Imports the PyOTA libraryfrom iota import Iotafrom iota import Address# Setup PIN'sLEDPIN=18GPIO.setmode (GPIO.BCM) GPIO.setwarnings (False) GPIO.setup (LEDPIN,GPIO.OUT) GPIO.output (LEDPIN,GPIO.LOW) # Function for checking address balance on the IOTA tangle. Def checkbalance (): print ("Checking balance") gb_result = api.get_balances (address) balance = gb_result ['balances'] return (balance [0]) # URL to IOTA fullnode used when checking balanceiotaNode = "https://nodes.thetangle.org:443"# Create an IOTA objectapi = Iota (iotaNode) ") # IOTA address to be checked for new light funds # IOTA addresses can be created using the IOTA Walletaddress = [Address (baked GTZUHQSPRAQCTSQBZEEMLZPQUPAA9LPLGWCKFNEVKBINXEXZRACVKKCYPWPKH9AWLGJHPLOZOYTALAWVSIIYVZ')] # Get current address balance at startup and use as baseline for measuring new funds being added. Currentbalance = checkbalance () lastbalance = currentbalance# Define some variableslightbalance = 0balcheckcount = 0lightstatus = False# Main loop that executes every 1 secondwhile True: # Check for new funds and add to lightbalance when found. If balcheckcount = = 10: currentbalance = checkbalance () if currentbalance > lastbalance: lightbalance = lightbalance + (currentbalance-lastbalance) lastbalance = currentbalance balcheckcount = 0 # Manage lightbalance and light ON/OFF if lightbalance > 0: if lightstatus = = False: print ("light ON") GPIO.output (LEDPIN GPIO.HIGH) lightstatus=True lightbalance = lightbalance-1 else: if lightstatus= = True: print ("light OFF") GPIO.output (LEDPIN,GPIO.LOW) lightstatus=False # Print remaining lightbalance print (datetime.timedelta (seconds=lightbalance)) # Increase balance check counter balcheckcount = balcheckcount + 1 # Pause for 1 sec. Time.sleep (1) runs the code
To run the above code, we need to save it to a file on a raspberry pie, such as let_there_be_light.py. Then use the following command:
Python let_there_be_light.py
You should now see the code executing in the terminal window, showing the current balance, and checking the balance of the IOTA address corresponding to LED every 10 seconds.
Pay for the use of LED
To light up LED, you just need to use your favorite IOTA wallet to transfer some IOTA coins to LED's IOTA address. As long as the transfer transaction is confirmed by IOTA tangle, LED should light up and until the balance is consumed. In my demo, I set the charge for 1 IOTA per second.
This is the end of the content of "what is the method of Python iota hardware integration". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.