0
Good afternoon, I got an error message from Coul operands not be broadcast Together with shapes (256,) (268,) image shows the error
the code is as follows::
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
import math
import string
import numpy as np
def dec_to_bin(ascii):
binary=format(''.join('{:04b}'.format(x) for x in ascii))
bits=np.transpose( list(map(int, np.transpose( list(binary)))))
return bits
def convert_to_ascii(text):
aux=format(''.join(str(ord(char)) for char in text))
ascii= list(map(int,list(aux)))
return ascii
#===============Inicialização Radio do NRF24L01=======================
GPIO.setmode(GPIO.BCM)
pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1], [0xF0, 0xF0, 0xF0, 0xF0, 0xE1]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setCRCLength(NRF24.CRC_DISABLED)
radio.setPayloadSize(32)
radio.setChannel(0x76)
radio.setDataRate(NRF24.BR_1MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(False)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openReadingPipe(1, pipes[1])
radio.disableCRC()
#radio.printDetails()
radio.startListening()
#========palavra a receber===================
palavra="01234567890123456789012345678910"
#==============Texto inicio programa===================
print("\n")
print("====Inicio Envio Dados Sensor2======")
time.sleep(.1)
print("\n")
#=======Conversao (palavra)==================================================
ascii=convert_to_ascii(palavra)
ascii_aux=np.array(ascii)
erros=np.sum(np.array((np.array(ascii)-np.array(ascii_aux))!=0, dtype=int))
bits=dec_to_bin(ascii)
#print("Bits(palavra)=",' '.join('{:04b}'.format(x) for x in ascii))
##print('Bits(array)= ',format(','.join('{}'.format(x) for x in bits)))
#=======================Mensagem Recebida====================================
while(1):
while not radio.available(0):
time.sleep(1 /100)
receivedMessage= []
radio.read(receivedMessage, radio.getDynamicPayloadSize())
string = ""
for n in receivedMessage:
string += chr(n)
ascii=convert_to_ascii(string)
ascii_aux2=np.array(ascii)
bits_rx=dec_to_bin(ascii)
## print("recebido", ascii_aux2)
## print("palavra_", ascii_aux)
print("Bits(recebidos)=",' '.join('{:04b}'.format(n) for n in ascii))
erros=np.sum(np.array((bits-bits_rx)!=0, dtype=int))
print("Erros= ", erros)
What is
bits
andbits_rx
? And what is the expected result of the subtraction of the two?– Woss
Bits is the word variable written in binary, bits_rx is the word received from Arduino for the converted pi Raspberry binary , then the operation is performed to know the number of wrong bits in the total of each transfer every 5 seconds
– Sergio Nunes