![]() In the new script I imported the first code - import FirstCode as FC and then used the SendSignal command as FC.SendSignal (0,1,0,1). #Envoyer a doc quand il y a de la communicationĬreating and using a python module for sending byte signal I imported the first mentioned code to the new script and tried to use its SendSignal command as the result, I receive Errno9 on the rx_data = spi.xfer2(tx_data) section. ONcommunication_line = 'Communication State ON' #Preparer un messagae quand il y a de la communication #Envoyer a doc quand pas de la communication OFFcommunication_line = 'Communication State OFF' #Preparer un messagae quand pas de la communication #Envoyer et attendre pour recevoir signal quand pas de la communication With open('/home/RPiUser/Documents/Prog/SPI/SPI_StatusDoc', 'w',encoding='utf-8') as file: With open('/home/RPiUser/Documents/Prog/SPI/SPI_StatusDoc','r', encoding='utf-8') as file: Print("COMMUNICATION ERROR! RETURN SIGNAL LOST OR CORRUPTED!") How is it working so far? Fortunately, all of the code done is functioning. ![]() It uses the SendSignal fucntion to repeatadly send signal until it receives an answer from the microcontroller. Before all of the text document shenanigans, there rx_data awaits for the microcontroller to send back a specific byte signal (1 aka 0b00000001) in order to confirm that the two devices are still communicating with each other.ĭebutTeste is the function that checks whether there is communication between two devices or not. Later on the function, the pin state is printed on the separate text document. At the end the tx_data is sent as the signal through the rx_data = spi.xfer2(tx_data). Later the arguments are connected together into one byte as the tx_data variable. tx_pin array is there to connect the function SendSignal with the earlier mentioned list (is this an extra step? possibly).įunction SendSignal just as the name suggests send the signal from RPi to microcontroller the function demands to specify what pin (PIN) to use, to Input or Output it (IO), to keep High or Low (HL) and whether the to take the command into action (AI, earlier mention 8th bit keep it as 1). The list, that goes from pin 0 - 27, is there to tell the 5 bits used to find the pin used. How does the code work? The following code consists of list, array and two functions. The communication utilises encoded byte signals, where first 5 bits determine the pin, 6th bit tells whether the pin send High or Low signal, 7th bit determines whether the pin is Input or Outputand 8th bit always stays 1 to insure that the command is taken into action. Software wise on RPi I am using python with SpiDev and time libraries, and on microcontroller I am using Arduino IDE with SPI.h library. RPi and microcontroller are connected through CIPO, COPI, CS and SCLK (for old-fashion folks, the first three are MISO, MOSI and SS). RPi and microcontroller communication Context: The communication is done through SPI. ![]() The idea is that RPi tells microcontroller what sorts of actions on the I/O should be done, and in case of the short-circuit, microcontroller gets damaged instead of RPi, thus protecting RPi and its pins. General Context: I am working on project where the SBC (in my case, Raspberry Pi 4) has its pins protected from possible short-circuits due to the sloppy wiring those pins are protected with microcontroller (in my case, it is an analog of Arduino Mega 1280 from DFRobot).
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |