ESP32 Pixelflut client
This is a very simple (but unoptimized) pixelflut client for the ESP32, just change the WiFi credentials, add your pixelflut’s server url and port, add an image to your SD card named image.jpg
(you can rename it and modify code as you wish), and connect it to the board’s SD card reader.
1#include "WiFi.h"
2#include <SD_MMC.h>
3#include <TJpg_Decoder.h>
4
5
6const char* ssid = "....";
7const char* password = "....";
8const char* server = "....";
9int port = ....;
10
11
12#define SD_DATA 40
13#define SD_CLK 39
14#define SD_CMD 38
15
16
17const char* image = "/image.jpg";
18
19
20WiFiClient client;
21
22
23void initWiFi() {
24 WiFi.mode(WIFI_STA);
25 WiFi.begin(ssid, password);
26 Serial.print("Connecting to WiFi ..");
27 while (WiFi.status() != WL_CONNECTED) {
28 Serial.print('.');
29 delay(1000);
30 }
31 Serial.println(WiFi.localIP());
32}
33
34void initSDCard() {
35 SD_MMC.setPins(SD_CLK, SD_CMD, SD_DATA);
36 if (!SD_MMC.begin("/sdcard", true)) {
37 Serial.println("Card failed, or not present");
38 return;
39 }
40 Serial.println("SD card initialized via SDMMC.");
41}
42
43bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) {
44 for (int16_t i = 0; i < w * h; i++) {
45 uint16_t color = bitmap[i];
46
47 uint8_t r = (color >> 8) & 0xF8;
48 uint8_t g = (color >> 3) & 0xFC;
49 uint8_t b = (color << 3) & 0xF8;
50
51 char colorHex[7];
52 sprintf(colorHex, "%02X%02X%02X", r, g, b);
53
54 client.print("PX ");
55 client.print(x + (i % w));
56 client.print(" ");
57 client.print(y + (i / w));
58 client.print(" ");
59 client.println(colorHex);
60 }
61
62 return true;
63}
64
65void setup() {
66 Serial.begin(115200);
67 initSDCard();
68 initWiFi();
69
70 if(!client.connect(server, port)){
71 Serial.println("Connection to host failed");
72 delay(1000);
73 return;
74 }
75
76 Serial.println("Connected to pixelflut server successfully");
77
78 File jpegFile = SD_MMC.open(image);
79
80 TJpgDec.setJpgScale(1);
81 TJpgDec.setCallback(tft_output);
82
83 uint32_t t = millis();
84
85 if (TJpgDec.drawSdJpg(400, 0, jpegFile) != 0) {
86 Serial.println("Failed to decode JPEG");
87 }
88
89 t = millis() - t;
90 Serial.print("Done! took ");
91 Serial.print(t);
92 Serial.println(" ms to complete");
93 client.stop();
94}
95
96void loop() {
97
98}
code explanation
honestly i dont remember how this works.