A random thought

How can you figure out a dynamic ui layout based on sensor data that has been just now added, where previous the interface had no idea from?
113 Replies
Rägnar O'ock
Rägnar O'ock3w ago
i think you'll need to add more context, like what ui, what sensor, why responsive design is not enough...
ἔρως
ἔρως3w ago
what do you want to show from the sensor? and how?
Kingpin
KingpinOP3w ago
Like for school my team are gonna build a modular board where you can click in your sensors that will automatically be connected to the Arduino. Using i2cscanner library I can apparently dynamically detect new sensors being added and display the name on the interface. Each sensor would get it's own detail page showcase their own values in a nice way (not just plain text). Since every sensor has it's own unique data that can be displayed several ways some of them are more appropriate then others. So how can be UI be dynamically build nicely when adding these new sensors. For the assignment we gonna fully configure 2 sensors and 2 actuators (these are hard requirements) and display the data properly. As extra it would be nice to somehow allow the user add random sensors to it and the data gets displayed properly (potentially with an editor they could then use the values to make actual changes to the behaviour of the Arduino themselves).
vince
vince3w ago
I've been working with web components for the past month, so when you have a hammer everything looks like a nail...
class SensorLayout extends HTMLElement {
#config = {}; // Sensor config

constructor(sensorData) {
this.#config = sensorData; // Pass in data from Arduino
}

connectedCallback() {
// Render your layout
const layoutType = this.#config.type;

switch (layoutType) {
case "type-1":
this.innerHTML = this.#renderTypeOne();
break;
case ...
}
}
}
class SensorLayout extends HTMLElement {
#config = {}; // Sensor config

constructor(sensorData) {
this.#config = sensorData; // Pass in data from Arduino
}

connectedCallback() {
// Render your layout
const layoutType = this.#config.type;

switch (layoutType) {
case "type-1":
this.innerHTML = this.#renderTypeOne();
break;
case ...
}
}
}
Still needs more context, but would something like that work ^ and I'm assuming you want very specific layouts for each type; if you just want some parts of your layout to change then I'd make each of those parts a component and pass in the data from your Arduino and display based off type like I'm doing above
Kingpin
KingpinOP3w ago
I don't think these sensor has the types, but I can add a add sensor button where they can add the newly added sensors they can select the autogenerated one. This would go to an edit page where they could add a type to the various input values and even add a thumbnail voor the image.
ἔρως
ἔρως3w ago
basically, you want something like an home assistant dashboard?
Kingpin
KingpinOP3w ago
In a way. Definitly a dashboard. Idk how else to explain it.
ἔρως
ἔρως3w ago
and how do you want to display the information?
Kingpin
KingpinOP3w ago
Some data make sense as a graph others as a number, some as a switch.
ἔρως
ἔρως3w ago
other data as a gauge, other as multiple formats
Kingpin
KingpinOP3w ago
Uhu, that's the unpredictable part. We don't know what sensors they would be adding. One why to solve it is like vince figure out the type and then display the data according to that type.
ἔρως
ἔρως3w ago
it's not really if you have a list of sensor and capabilities, then each capability has different ways of being represented, then you are set for example, a temperature sensor that can also report relative humidity you can show the temperature and the humidity in a percentage but a sensor that doesn't have humidity just doesn't show humidity it also depends on how granular you want to be or you can do the inverse: you can show a temperature then pick sensors capable of reporting temperatures
Kingpin
KingpinOP3w ago
But the thing is we don't know what that list is, we can have a list of the sensors that we will do for the assignment specifically but what if the users adds a sensor that we don't know about?
ἔρως
ἔρως3w ago
you can either request the sensor it's capabilities or you manually assign them based on a list you have
Kingpin
KingpinOP3w ago
Will the i2cscanner automatically receive the data with their types?
ἔρως
ἔρως3w ago
that's a good question
Kingpin
KingpinOP3w ago
Ik it does the names or at least an id thing that you can use with a lookup from a quick research. I will watch a video about it at some point. If that's the case we gotta make several components for several types and then display that component when that type is requested.
ἔρως
ἔρως3w ago
i've never tried to do a lot with i2c most i did was to connect a 4-pin display to a raspberry pi pico
Kingpin
KingpinOP3w ago
Did you even needed i2c for that? Xd
ἔρως
ἔρως3w ago
i think it is i2c maybe it was spi
Kingpin
KingpinOP3w ago
To my understanding i2c loops over your pins to detect how many sensors are connected with like ID or something.
Kingpin
KingpinOP3w ago
I need to get myself more familiar to what i2c can do.
vince
vince3w ago
If I'm understanding correctly why don't you make a 'map' of types to each id?
switch (id) {
case 1:
return { sensorId: 1, sensorType: "type-1" };
...
default:
return { sensorId: 0, sensorType: "default" };
}
switch (id) {
case 1:
return { sensorId: 1, sensorType: "type-1" };
...
default:
return { sensorId: 0, sensorType: "default" };
}
ἔρως
ἔρως3w ago
not all sensor types are equal for example, temperature sensors sometimes can give you relative humidity or air pressure
vince
vince3w ago
Can't you just look at the type of data it gives you then and map it based off that?
ἔρως
ἔρως3w ago
it's not like you get a binary chunk that says "temperature"
vince
vince3w ago
if (sensorData.hasOwnProperty("humidity") Ohh yea that's interesting I have no idea about any of this stuff I'm just spitballing from JS world lol
ἔρως
ἔρως3w ago
from my understanding, some sensors work by sending a byte and you get data or a few bytes, depends
vince
vince3w ago
Can JS work at the byte level? Or would you even want to work at the byte level with JS?
ἔρως
ἔρως3w ago
yeah with bitwise operations
vince
vince3w ago
I know there's bit shifting but I've never touched that That sounds like a chatGPT operation to me 😄
ἔρως
ἔρως3w ago
also, not all sensors send the data the same way
vince
vince3w ago
that sounds like a fun project honestly i love doing that stuff, like the organizational parts to map the code cleanly
ἔρως
ἔρως3w ago
it does
Kingpin
KingpinOP3w ago
Receiving the data from Arduino gonna be with C for Arduino. The. The processed data will be send via a broker so I can receive it with js to display it in the interface. Ye, I love fully dynamic systems.
vince
vince3w ago
Are you making the broker?
Kingpin
KingpinOP3w ago
Prolly ye a local one, apparently it's not hard to setup. A classmate did it for us for an class assignment when we worked together (different person),he did it in like a couple minutes. Cuz it's gotta be usable locally without wifi.
vince
vince3w ago
Oh nice so sounds pretty easy from a mapping perspective So it's just mapping that data correctly in the broker to be nicely ingestible via JS
Kingpin
KingpinOP3w ago
That depends on what i2c actually returns.
vince
vince3w ago
I figured the broker would be robust enough to not be a headache 😭
Kingpin
KingpinOP3w ago
I actually only know about i2c from a question I asked to Gemini haha.
vince
vince3w ago
haha yea I haven't heard abt it til now
Kingpin
KingpinOP3w ago
If the i2c returns the data with it's types and the sensor name then it's just about sendin the data via the broker and using a switch case like you showed. If it doesnt returns the data with it's types then it's gonna be more difficult I think. This project sounds both as really easy but also insanely difficult at the same time lmao. But me and my classmate are confident in it.
ἔρως
ἔρως3w ago
or just have a way to also manually assign capabilities to the sensor
Kingpin
KingpinOP3w ago
We will also have to design the main board that will house an Arduino and maybe some click system to connect extra boards to it etc. Apparently the i2cscanner returns the i2c addresses, I am guessing these are the onces from each sensor that are connected?
ἔρως
ἔρως3w ago
technically, no
Kingpin
KingpinOP3w ago
Wdym?
ἔρως
ἔρως3w ago
that it simply shows the address of something in the bus
Kingpin
KingpinOP3w ago
Right, but it's only things that are connected physically to the Arduino right?
ἔρως
ἔρως3w ago
yes but it can be a whole sensor or part of a sensor for example, a temperature sensor could have 2 addresses - one for temperature, one for humidity
Kingpin
KingpinOP3w ago
Ah, actually that's nicer.
ἔρως
ἔρως3w ago
it depends on the sensor some may require commands, some may have 2 different addresses you have to read the documentation
Kingpin
KingpinOP3w ago
I2C Addresses and Troublesome Chips
I2C addresses from 0x00 to 0x7F (inclusive). Flaky I2C devices.
Kingpin
KingpinOP3w ago
@vince 🙂
ἔρως
ἔρως3w ago
that's mostly a list of products that adafruit sells, which is understandable
Kingpin
KingpinOP3w ago
We have to buy our sensors anyways still we don't have the onces that we need. Except for the ultrasonic sensor. According to an official Arduino server mod adafruit doesnt make ics.
ἔρως
ἔρως3w ago
which is exactly what i didn't say
Kingpin
KingpinOP3w ago
Ah ig they don't make em but they sell them. Ig I just translated that if I where to buy that module somewhere else that it wouldnt work.
ἔρως
ἔρως3w ago
no, it's just products that they have they do assemble some, somehow they have their own brands of stuffs
Kingpin
KingpinOP3w ago
But I didn't had to buy my sensors via them for the addresses to be same right? Like if the list has an address for an ultrasonic sensor it's gonna be the same for the one I already have?
ἔρως
ἔρως3w ago
i don't know check the manufacturers' site, not a """"random"""" list of sensors from a specific vendor
Kingpin
KingpinOP2w ago
We prolly gonna be using NFC tags and configure the IDs ourselves. Gonna make housings for the sensors seperatly that can be connected to the board.
ἔρως
ἔρως2w ago
which type of nfc tags?
Kingpin
KingpinOP2w ago
No idea yet, was talking to someone who gave that idea. Cuz NFT tags don't use power and send only IDs.
ἔρως
ἔρως2w ago
yeah, and then what do you do?
Kingpin
KingpinOP2w ago
Nothing yet? I am just thinkering around.
ἔρως
ἔρως2w ago
and you had any ideas for it? can you store anything in those?
Kingpin
KingpinOP2w ago
In the NFT tags? Me was told it cant send any data only IDs which I actually think is weird. Cuz headphone and smartphones have NFC for audio. Need to dive deeper into it.
ἔρως
ἔρως2w ago
it depends on the tag the cheapest of the cheap tags only send an id, others can send some data
Kingpin
KingpinOP2w ago
If I can send the data over with NFC I can make it so it can use just one wire to the board for power. Which possibly simplifies a lot of things.
ἔρως
ἔρως2w ago
remember that nfc doesn't send much data, and not for a long distance im talking about 1cm or so
Kingpin
KingpinOP2w ago
Ye ik, but it's all relatively close to each other anyways. NFC can do further then 1cm tho. But jg that depends again on the NFC tag itself. I think NFC/bleutooth is the way to go.
ἔρως
ἔρως2w ago
nfc, if you can write to it, is amazing for 1 thing: storing configs
Kingpin
KingpinOP2w ago
I mean that's all it gotta do for the project no? Actually doing calculations etc is happening via the dashboard. Arduino is just gonna send over the data in a consistent manner. If NFC doesnt work I can use a bleutooth module. Me and my teammate can*
ἔρως
ἔρως2w ago
there's probably easier, like matter, zigbee or others or thread
Kingpin
KingpinOP2w ago
They do similar? Sending data wirelessly?
ἔρως
ἔρως2w ago
similar to bluetooth
Kingpin
KingpinOP2w ago
Ah gotcha, ye we definitly gonna look into what's gonna be easiest to use and what makes sense for the product. I still think the sensor needs to be physically connected to the module that will do the data transfers and each sensor has different amount of pins that do different things. That's the trickiest part.
ἔρως
ἔρως2w ago
that's the thing: it can have it's own power
Kingpin
KingpinOP2w ago
Ye but having a battery for each sensor is gonna get expensive fast (I think), I'd rather have one centralized bigger battery.
ἔρως
ἔρως2w ago
not at all cr2032 are cheap as fuck
Kingpin
KingpinOP2w ago
Oh those batteries.
ἔρως
ἔρως2w ago
or even AA or AAA batteries
Kingpin
KingpinOP2w ago
How long do they laste tho? Also are they rechargable?
ἔρως
ἔρως2w ago
they last months and years, and they may or may not be rechargable it depends on the battery, battery quality and how much power you use
Kingpin
KingpinOP2w ago
Hmm, honestly having wirelessly connected sensor modules sounds a lot cooler. If we gonna be using batteries I want them to be regarchable less e-waste and all. They should be easy to remove but also not by accident. I am liking where this is going
ἔρως
ἔρως2w ago
you can look for cr2032 batteries that are rechargable you can use small and expensive lithium batteries you can also use 18650 batteries
Kingpin
KingpinOP2w ago
Honestly ye we might, they're more expensive but we can leave an opening for a usb-c cable to be plugged in the housing if needed. Then they don't have to reassmble there things potentially in order to charge the sensors.
ἔρως
ἔρως2w ago
you will need to buy charger circuits
Kingpin
KingpinOP2w ago
We will have to make a list of things we need anyways. Motors, camera sensor, wireless module (still need to be discussed what type), lamps, batteries, charger circuits. Also whatever is discussed here isn't final, still need to be talked to with my teammate. We have like 2 months-ish
ἔρως
ἔρως2w ago
there's a lot of alternatives for batteries you can also do what some people do: find disposable vapes and take the batteries off of it
Kingpin
KingpinOP2w ago
We can 3D model housings for like 2 pins 3 pins 4 pins, if you have a sensor for 4 pins you 3D print a housing for 4 pins and you would be able to click the sensor in it or something. Each of the housings will have some type of wireless data transfer module, a battery (preferably small and/or rechargable) and a resistor if needed. Some of the sensors/actuators etc, are square some of them rectangle the pins aren't always on the same place.
ἔρως
ἔρως2w ago
basically like lego for sensors?
Kingpin
KingpinOP2w ago
There will be connection points for lego/knex whatever you want so in a way yes, lego for sensors. We cant make a housing for each sensor individually, but we can potentially design a base for it and then the surroundings can be custom made specifically for the needs for the sensors. I really hope this works out lol
ἔρως
ἔρως2w ago
do you have to do a presentation later on?
Kingpin
KingpinOP2w ago
Ye, gotta be like a kickstarter type thing.
ἔρως
ἔρως2w ago
that is interesting
Kingpin
KingpinOP2w ago
I was wondering, we have to make a webinterface for it using a broker. We already decided that we gonna build a dashboard for it not an actual website. If we store the data from each sensor/actuators in objects per sensor/actuator and make them globally available, we could embed a code editor from a package and users can access the values through code via that. So they can read/write code to the correct sensors/actuators.
ἔρως
ἔρως2w ago
if you can make it work with js or python, would probably be really cool
Kingpin
KingpinOP2w ago
Definitly gonna be js.
ἔρως
ἔρως2w ago
basically, you want to write something that lets people control servos and stuff from the web ui?
Kingpin
KingpinOP2w ago
Ye, if I understand the word "servos" correctly. Basically having it's own development platform for IoTers to build on. Which is gonna be easier I think then using Arduino IDE since their you need to figure out what pin the sensor is connected to etc. Here it will already know.
ἔρως
ἔρως2w ago
"servos" means "servo motors"
Kingpin
KingpinOP2w ago
We gonna be using motors for the car. We are sticking to the grove system Our cost for the project €43,11
ἔρως
ἔρως2w ago
that's not bad at all
Kingpin
KingpinOP2w ago
Gonna be closer to 53,09 but still alright. We miscounted xd. Not including the 3D printed parts, but we can use the onces from school for free.
ἔρως
ἔρως2w ago
that is still a pretty nice price
Kingpin
KingpinOP2w ago
Did you used react? Idk if you know a component library for charts that we could use? Like line chart etc. I can see some online but idk if there is a "go-to" one.
ἔρως
ἔρως2w ago
i've only used it for wordpress' shitty ui on the admin page i can't help with that, and you should make a different post for that
Kingpin
KingpinOP2w ago
It's for the same project tho but ig I just should make a showcase thread in the forum.
ἔρως
ἔρως2w ago
i mean, a new post in #help to ask about a component library with charts
Kingpin
KingpinOP2w ago
Yikes forgot about shipping fees, is 69,32 without the motors (nice tho xd).

Did you find this page helpful?