How to make text to speech on Raspberry Pi Pico W - out-of-memory

I am trying to to make a simple voice assistant using python. However, after months of hard work, I realized that the TTS I was using (pyttsx3) will not load onto the Raspberry Pi Pico W. Is there any way to get TTS on the Pico?
I have tried using the Hugging face inference API for my code, so I used this snippet:
import network
import socket
import machine
import urequests as requests
ssid = 'My Wi-Fi network '
password = 'My Wi-Fi password'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
print("internet connected sucessfully")
API_URL = "https://api-inference.huggingface.co/models/facebook/fastspeech2-en-ljspeech"
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": "The answer to the universe is 42",
})
(Note that in my real code I put my actual API token and Wi-Fi password)
However, every time I run the code (with actual API token) it gives me the same error:
internet connected sucessfully
Traceback (most recent call last):
File "<stdin>", line 20, in <module>
File "<stdin>", line 17, in query
File "urequests.py", line 33, in json
File "urequests.py", line 20, in content
MemoryError: memory allocation failed, allocating 119296 bytes
what should I do?

The problem is the data volume it overpass the SRAM memory.
Please check out the Raspberry Pi Pico components and checkout what is a microcontroller. You always need put a program into a flash memory and create a comunication protocol, if you want use the Raspberry Pi Pico remotely.
https://datasheets.raspberrypi.com/pico/pico-product-brief.pdf
https://raspberrypi.github.io/pico-sdk-doxygen/modules.html

Related

WebIOPi no connection with I2C device alert

I am working with WebIOPi on a Raspberry Pi 2. The raspberry is connected to an Arduino Nano via I2C (Python script working well with the Nano - a button from a web page can turn on or off LEDs).
Is it possible to make a diagnostic Javascript alert when the connection with the Arduino is broken (if line/wire I2C is broken)?
Thank you.
solved in low level (python script + return some value).
Example python script:
try:
bus.write_byte(address, int(value))
time.sleep(0.01)
number = bus.read_byte(address)
flag = number
except IOError:
number = 11 #error value (my fantasy)
flag = number
"flag" variable used in javascript to recognize connection status and if flag = 11 then comes alert("no connection")

RSSI value using MicroPython in NodeMCU ESP8266

How to get the RSSI value of the WLAN device connected to WiFi of my NodeMCU device using MicroPython? Actually I tried the following code but I'm getting an error:
>>> sta_if.ifconfig()
('192.168.1.103', '255.255.255.0', '192.168.1.1', '192.168.1.1')
>>> sta_if.rssi()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'WLAN' object has no attribute 'rssi'
I don't know what I should do to get the RSSI value of the network.
From the WLAN class documentation:
wlan.scan()
Scan for the available wireless networks.
Scanning is only possible on STA interface. Returns list of tuples with the information about WiFi access points:
(ssid, bssid, channel, RSSI, authmode, hidden)

Pymodbus Failed to Connect with PLC Slave and Raspberry Pi Master

I am trying to use a Raspberry Pi 3 Model B to read values from an Allen Bradly PLC. I'm using the Pymodbus Modbus TCP protocol to communicate between them.
When I run a test client I get the following error:
pi#raspberrypi:/var $ python test1.py
Got here 1
Traceback (most recent call last):
File "test1.py", line 12, in <module>
request = client.read_holding_registers(0,1)
File "build/bdist.linux-armv7l/egg/pymodbus/client/common.py", line 109, in read_holding_registers
File "build/bdist.linux-armv7l/egg/pymodbus/client/sync.py", line 82, in execute
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[10.0.0.237:502]
Here is the code for the test client:
from pymodbus.client.sync import ModbusTcpClient
#modbus connection
client = ModbusTcpClient(host='10.0.0.237')
connection = client.connect()
#test print
print "Got here 1"
#read register
request = client.read_holding_registers(0,1)
print request
client.close()
I can ping the IP address of the PLC's ethernet card (10.0.0.237) just fine. (The PLC is on and shows up in RSLinx and RSLogix5000.) But when I try to check port 502 (which Modbus uses) with the command:
telnet 10.0.0.237 502
I get the error:
Trying 10.0.0.237...
telnet: Unable to connect to remote host: Connection refused
The research I've done told me to check whether that port is open, but that is for PCs, I don't know how you check/configure the ports on a PLC.
In addition, I am wondering if the problem is that I am trying to just use Modbus to go between the Raspbery Pi and PLC. I have found prosoft gateways that do the interfacing. But I couldn't find any information on whether those were just another option or whether they were required.
I am new to PLCs and networking, so any help would be appreciated.
I have not used Allen Bradley myself but I do use a multitude of other PLCs though and they all work more or less the same.
You dont open the port as you would in a router but rather activate modbus connectivity in the PLC. Most often its a setting but if Allen Bradley use their own proprietary bus system (e.g Saia S-Bus) you sometimes need a specific function block to enable modbus.
A quick google search for example showed that in micrologix 1400 theres a checkbox to enable modbus tcp under some channel setting.
Check in the PLC if there is a setting to enable modbus master/client (master=serial or RTU, client=TCP but sometimes manufacturers dont differentiate them).
To test the Raspberry Pi you can download a modbus server simulator and poll that.
To test the PLC with something other then the Pi you could download a modbus client/master. I personally use QmodMaster which is free and works well for testing purposes (search google).
Also, make sure youre polling using the right function code. This can be confusing as holding registers (which are addressed 4xxxx) use function code 03. Input registers (which are addressed 3xxxx) use function code 04.
A modbus gateway is used to enable serial modbus (RTU or ASCII) to communicate via TCP.
If both devices do have modbus tcp theres no need for a gateway. If for example you have a device which only has wired modbus (RS232/485/422) you can connect that to a gateway and the gateway to TCP.

detect end of file in pyserial python3

I have been searching this, but couldn't get a good answer.
i have to send a file through COM port between two PC.
but i dont know how to detect the end of file.
In PC 1 i use teraTerm software to send file.
In PC 2 is use the following python code.
After the file is sent i need to put some message that the file is complete.
import serial
ser = serial.Serial('COM1')
ser.flush_input_buffer()
file = open('file.txt','a') #open empty file for appending
while True:
receivedByte = ser.read() # read 1 byte
file.write(receivedByte)
if (#detect end of file ):
break
print('file received')
Please note : PC is windows 8.1, Pyserial, Python 3.4
Please also suggest for Linux file
There is no EOF for a serial port as such. And what I can gather from the Internet teraTerm doesn't have a protocol for sending files, but just sends them in their raw form.
You could maybe set the read timeout for the serial port, so that the read would raise a SerialTimeoutException when there is no data left.
I tried this solution, although it is not as elegant and rather simple. It does work.
receivedByte = ser.read() # read 1 byte
while receivedByte != b'':
file.write(receivedByte)
receivedByte = ser.read()
print('file received')

How Can IBM Bluemix Node-RED Iotout node be set up correctly to send command to Device (Arduino)?

I have an Arduino Uno that is successfully registered as a device with IBM IoTF. It can send information to the Bluemix Node-RED app without any issues now.
Now, I would like the Node-RED app to send commands to the device (the Arduino Uno). The Arduino is subscribed to the MQTT without any error. But, it is not receiving any commands from the Node-RED. I followed the directions at the link below to create another flow in Node-RED to show when a command is published and the commands are being shown, so they seem to be going to the MQTT broker. But, the device (Arduino) is not receiving them.
How can I figure out how to get this working?
Node-RED, IOT Foundation Out Node Not Sending Commands
I have the IBM IoT Out Node parameters set as follows:
Authentication: Bluemix Service
Output type: Device command
Device type: Arduino-tempsensor (this is the same string I used for the device type (name) when I registered it in IoTF)
Device ID: I put the MAC address here, should it be more
Command Type: status (I used the word "status" here. Does capitalization matter? Where should I get this value from? I used "status" because it is in the topic: "iot-2/cmd/status/fmt/json" is that correct?)
Format: json (does capitalization matter here?)
data: {"d":{"myName":"Arduino Uno", "temperature":989}} (I used this because it's JSON and I wanted to just see anything at the device)
Name: IBM IoT App Out
I typed up this whole question and then it occurred to me that the test flow to look for the published command should have all of the parameters set to exactly the same as the output. When I tried that, I was not getting the command message coming back. Then, I realized that my mac address (device ID) was capitalized in one place, but not the other. The MAC address (Device ID) I used to register the device was all in caps, so I make the Iot-out node for the command so that it was all capitalized and made the Iot-in node to test for the message so that it was all capitalized. Now it works! Then, I looked back at the device (which was printing to the serial monitor so I could see what was happening) and I am now seeing the messages! So, make sure your parameters follow the same capitaliztion!

Resources