koukatsuwu
July 30, 2024, 04:55

(Arduino) Trying to send a web request with OpenAI API

cpp
# include <WiFi.h>

char  ssid = "";
char  password = "";
char * key = "Bearer "; 
//pretend these were filled out

void setup() {
    Serial.begin(9600);
    if (!Serial) { delay(5000); }
    Serial.print("Connecting to WiFi\n");
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) { continue; }
    Serial.print("Connected!\n");
    WiFiSSLClient client;
    Serial.print("Connecting to OpenAI\n");
    if (!client.connectSSL("api.openai.com", 443)) {
        Serial.print("Connection failed!");
        return;
    }
    Serial.print("Connected!\n");
    String payload = "{\
model: gpt-3.5-turbo,\
messages: [{\
role: system,\
content: Why is grass green?\
}]\
}";
    client.println("POST /v1/chat/completions HTTPS/1.0");
    client.println("Host: api.openai.com");
    client.println("Content-Type: application/json");
    client.print("Content-Length: ");
    client.println(payload.length());
    client.print("Authorization: ");
    client.println(key);
    client.println();//separate data from headers
    client.println(payload);
    while (client.available()) {
        char c = client.read();
        Serial.print(c);
    }
    if (!client.connected()) {
        Serial.print("disconnected\n");
        client.stop();
    }
}
This is the code I'm using ^^ I've tried a ton of stuff but I only ever get an error code 400.... For reference, here's the request working
bash
curl https://api.openai.com/v1/chat/completions   -H "Content-Type: application/json"   -H "Authorization: $KEY"   -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "Why is grass green?."
      }
    ]
  }'
^^ the above command actually returns a ChatGPT-generated response
wille____
July 29, 2024, 17:02

Control a led lamp using my phone with Bluetooth on rasp4

How can I control a led lamp connected to raspberry pi 4b using the Bluetooth on my phone?
ihatenetworkchuck
July 28, 2024, 21:55

make[1]: *** /lib/modules/6.1.21-v8+/build: No such file or directory. Stop.

make -C /lib/modules/6.1.21-v8+/build M=/home/dietpi/r8152-2.16.3 modules
make[1]:  /lib/modules/6.1.21-v8+/build: No such file or directory.  Stop. 
make:  [Makefile:24: modules] Error 2
shabzup
July 28, 2024, 14:44

Smart glasses project using raspberry pi zero wh

Hey, I am struggling with connecting and accessing my raspberry pi zero wh with ssh, i have done all the steps correctly but it does not connect to my wifi network, I have tried both 2.4GHz and 5GHz networks with a dual band wifi router
mathewb_06264
July 28, 2024, 14:21

tv tunner

Hi there is there anyone her who know anything about tv tunners.I would like to connect one to a cm4.
pweppapig2
July 28, 2024, 05:17

Pi 4B not booting

Hey! So I've gone through the troubleshooting sticky guide and I can't seem to figure out what's wrong with my pi. I'm getting 4 slow green blinks and then 7 fast ones which supposedly indicates that kernel.img is not found but I've properly formatted and then flashed my SD card MULTIPLE times with different OS's using the Raspberry pi imager. I have put the correct version of the OS (64 bit) so I'm lost now. What is wrong?
h_0_p
July 27, 2024, 22:11

Auto-Forcing the cursor to move to lower corner

I have a project that runs a python script when the pi boots up. When it boots, it checks how many days left until Halloween, and displays an image on the screen to reflect how many days left. It also spins 2 stepper motors ...This part works. The issue I am having is the cursor is displayed right smack in the middle of the screen, and I need it moved out of the way. This is going to run on its own with no mouse/kb installed. I've tried using the following methods:
python
pyautogui
  - attempt to move the cursor using pyautogui.moveTo(screen_width - 1, screen_height - 1)
xdotool via subprocess
  - subprocess.run(["xdotool", "mousemove", str(screen_width - 1), str(screen_height - 1)])
  - also tried to execute xdtool before initializing pygame:
      subprocess.run(["xdotool", "mousemove", "1919", "719"])
pynput
  - mouse.position = (screen_width - 1, screen_height - 1)
evdev
  - ui.write(e.EV_REL, e.REL_X, screen_width - 1)
    ui.write(e.EV_REL, e.REL_Y, screen_height - 1)
    ui.syn()
Nothing seems to make the cursor move out of the way - I am trying to move it to the lower right of the screen where it will be hidden. Any input is greatly appreciated.
spidertravler
July 27, 2024, 03:45

raspberry pi gadget mode

need assitance thanks
maric4648
July 26, 2024, 20:21

Raspi 5 not booting, 4 green blinks, no video

when i first booted my SD card that used to work on my rpi3 it got stuck at uboot, a little reading later i decided to just make the recommended SD with rpi-imager black screen only, 4 pulses (the last one is a bit clipped so maybe its 3+1 short?) booting without a card has the same behavior, nothing is shown on screen (not even the diag stuff?) i overwrote the sdcard that got stuck at uboot but i am at least 90% certain that my (only) microhdmi to hdmi cable didn't break any next steps? i couldn't find the blinking patterns for rpi5
lloyd.b
July 26, 2024, 12:41

NUT Server scanner On Pi Lacks Device Info

G'day All, This is a strange one and I'm not sure exactly where it belongs but I think it's more of a Raspberry Pi thing than a NUT thing. (Hopefully). The story so far...I have three UPS's and two of them are identical. The trouble is they do not have any unique information to differentiate between them. I can bypass this on Ubuntu because the nut-scanner utility reports a device ID (based on the port) which I can use to differentiate when writing the config. Alas, Bookworm (and Bullseye) do not seem to provide this information to nut-scanner. It does work if I install Ubuntu server on the Pi but that makes using the GPIO pins difficult and I'd really rather use Bookworm. The difference is that Ubuntu reports like this: [nutdev3] driver = "nutdrv_qx" port = "auto" vendorid = "0665" productid = "5161" product = "USB to Serial" vendor = "Cypress Semiconductor" bus = "002" device = "002" busport = "001" and Bookworm shows the same but without the device or busport entries. I can do without the busport entry but device would be fine. I've tried manually specifying the device ID from the results of lsusb but it doesn't work as I don't think it's aware of a device ID. Is this to do with the implementation of the usb lib stuff in Bookworm or would I need to install something extra on-top? I've scoured google and forums but to no avail as it seems people running it on Rpi have UPS's with serial numbers or other self-defining features. Would be grateful for a poke in the right direction. Cheers, Lloyd.
wille____
July 26, 2024, 11:32

transmit 433mhz signal with raspberry pi pico

Is it possible to use a Elecbee CC1101 Modul 433Mhz to transmit and receive a 433 mhz signal with the pico?
pipsqueeeek
July 26, 2024, 04:31

Emergency Shutdown Code

so I'm starting this project where I will use my raspberry pi 4b outside and leave it for 2 weeks minimum running on a solar panel. what bothers me the most is that if the battery suddenly runs out of power and improperly shutdown my raspberry pi it has a high chance of corrupting my raspberry pi. does anyone have suggestions on how I might make this work?
adrenasystem
July 26, 2024, 04:24

LF Help w/Programming Pi

Hi all! I'm looking for help on what to do to program my raspberry pi, I want to make some network security with it. Like auto closing ports, making sure our network has better encryption, defense against attacks.. what Pi do I get, where do I start? Needing some help.
m1gdal
July 25, 2024, 16:08

Simple KeyBoard project with RP2040

Hi, I'm creating a small USB stick project that will type a phrase on the screen when plugged into a USB port. I'm targeting the RP2040 or ATmega32U4. I'm more for the first one, but I'm curious if it would work well (or work at all).
doom5day
July 25, 2024, 03:44

moisturize sensor working with rasberry pi 5

any one know how to get a capacitive soil moisturize sensor working with rasberry pi 5? No clue how to program it
darthcheadle
July 25, 2024, 02:18

ultrasonic sensor not working

My ultrasonic sensor is not working with my raspberry pi

mendo2306
July 25, 2024, 01:55

Reboot problem?

Does anyone know why this happens and how to fix it? https://youtu.be/-5SVFRufPoo?si=aspKoLSH4dIbhkDz
rybeardawg
July 24, 2024, 01:58

PC Case Display - Looking for Advice

Hello! Overview I'm starting a project where I put computer thermals/vitals/stats and videos onto a display within my computer case and hoping to get any advice or pointers. Microcontroller I am between the RPI 4 Model B and the RPI Zero W. I will probably get the RPI 4 model B as it has a Mipi DSI interface and the RPI Zero W would require a converter. I want something with Wi-Fi so I can run an API from my desktop where the info it needs can be retrieved from there. Alternatively, I can use serial communication through the USB port but I think less wires and ports taken is ideal. Display Ideally, I'd like a display about 12" x 4" with a resolution around 1920x515. Can anyone recommend me something like this? When I've gone looking, I've only come across options with interfaces I don't think are compatible. Thank you for any advice!!
thunder07337
July 23, 2024, 23:05

Not sure if Zero W is loading the Raspberry Pi OS

You have misunderstood the instructions. It's about communicating with the Pi via the USB port instead of WiFi. It doesn't say anything about installing the OS on a USB stick.
catguy12321
July 23, 2024, 16:47

Pin busy

I'm trying to connect a RFM95W LoRa module and a button to a raspberry pi, but it returns a GPIO Busy error at CE1. I tried rebooting but still doesn't work. error message:
bash
Traceback (most recent call last):
  File "/home/raspberry/radio.py", line 11, in <module>
    CS = DigitalInOut(board.CE1)
         ^^^^^^^^^^^^^^^^^^^^^^^
  (redacted traceback stuff)
  File "/usr/lib/python3/dist-packages/lgpio.py", line 458, in _u2i
    raise error(error_text(v))
lgpio.error: 'GPIO busy'
code:
python
import time
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
import adafruit_rfm9x

btnA = DigitalInOut(board.D17)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP

CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

iter = 0

def send_data():
    global iter
    print("send %s"%iter)
    iter+=1

def get_data():
    global iter
    print("get %s"%iter)
    iter+=1

def main():
    try:
        while True:
            if not btnA.value:  # Button pressed
                send_data()
            else:
                get_data()
    except KeyboardInterrupt:
        pass

if __name__ == '__main__': 
    main()
iamnotmega_
July 23, 2024, 12:07

pi stopped working after dropping

i once dropped my pi on the floor and after it just refused to give an hdmi output. the case fan did spin when i had it connected, but when i tried to ssh into my pi, it said connection timed out. please help
leotgyt
July 22, 2024, 21:33

Pi 400 WLAN Adapter not detected

So, my Raspberry Pi 400 seems to be ignoring the integrated wlan0 adapter, showing only eth0 and lo in ifconfig. In the raspi-config menu, country locale setting fails with error "There was an error running option L4 WLAN Country" Although I have been trying out create_ap (hotspot, installed through pi apps) and rfkill, I don't think I've done damage. Any recommendations? Thanks in advance 🙃
gonzmacben
July 22, 2024, 18:18

Help with Installing GUI on Ubuntu server (24.04 LTS, Raspberry PI 5)

I got my first raspberry pi earlier this month and I am new to the hobby. I plan to use my PI with the usb c gadget functionality so I can connect it to my iPad pro and turn it into a "mini laptop" so I can work with ROS2, so far I managed to establish the ethernet connection but I haven't been able to install the GUI properly. I tried to use tigervnc and installed the ubuntu desktop minimal but the logs indicate that there are some problems with gnome I managed to create a vnc over ssh tunnel and the only thing I see is the white screen with the "Oh no! Something went wrong" message. I recently tried to install lightdm but it doesn't seem to work, the installation came with errors and I tried to fix it but it looks like it's just not compatible with my version. Has anyone managed to get the ubuntu 24.04 gui working on a Raspberry pi 5?
_skino
July 22, 2024, 17:22

Dual Noctua Fans

So im currently working on getting my Klipper installation back up and running on my Raspberry Pi but wanted to use two Noctua fans to avoid using the loud fans. its to add to the front of this case: https://www.fractal-design.com/north-pi-3d-files/ i want to use 2x Noctua NF-A4x10 5V but wanted to know if that's possible or not? and whats the best way to do it? Currently im cooling my Old Pi with some Noctua fans but im powering them with buck convertors directly from my PSU for my printer. Sorry if this doesnt make sense lol
vidrazevasa
July 22, 2024, 16:49

Argon Neo 4 Nvme Won't Fit

I have a Teamgroup MP33 Gen3 Nvme, and it doesn't seem to go in all the way or be recognized. I don't see the copper pins not going in all the way on anyone's build videos. How do I fix it?

birdboygee
July 22, 2024, 04:39

play store on linux keeps on crashing

i am trying the run the play store on linux ubuntu but it keeps on crashing any fix and what d bus do i need to use
darthcheadle
July 21, 2024, 21:15

keyboard not working raspberry pi zero w

I am using the micro usb to usb adapter that came with my zero w
arastotle
July 21, 2024, 17:11

CAM MODULE BLUE FILTER FIX

I connected the camera properly. How do I fix this?
darkbyte
July 21, 2024, 07:35

DAC with software switchable headphone and line output?

I'm trying to do my research and figure out if any audio HAT supports changing the output in software between the RCA line output jacks and the headphone output without having to unplug the headphone. It's not something the descriptions mentions unfortunately. Anyone have experience with this? eg. the Raspberry Pi DAC has pinouts for the headphone DETECT and MUTE pins, but I think that's hardwired together and will auto mute the RCA jacks once you plug in a headphone. https://www.raspberrypi.com/documentation/accessories/audio.html#raspberry-pi-dac Except maybe if the DAC chip supports ignoring the MUTE pin from it's firmware. There are some ALSA configuration files for the Raspberry DACs (previously IQAudio) which mention something like "Heaphone Switch" which is a changeable boolean value, though I'm not sure these actually do anything: https://github.com/raspberrypi/Pi-Codec/blob/master/Codec_Zero_Playback_only.state#L363 Can somebody with this HAT (or any other hat with an RCA + jack output) in hand test if you can toggle such thing from software, and check if it actually works?
leqitnyy
July 20, 2024, 23:24

Need help with shopping my for my first project

hello, i want to make a small project, lets say just LEDs blinking, second being controlling my audio on my pc with potentiometer. can you let me know if this is enough/am i missing something, should i buy something similiar, save money etc? also im not sure about the power of resistors, which should i choose? i dont want to spend 25$ for my project not working because of something. im a beginner so please go easy on me :). feel free to ask questions