I'm a total Arduino beginner, but I'm also a web developer so some parts of development is straight forward for me.
I have this project where I will be using a load cell to measure weight hanging in it.
I've done some research and come up with this plan (have yet to buy parts):
Arduino UNO board wired to a HX711 module, which in turn is wired to the load cell.
Arduino will in turn be connect via USB to computer.
I've read tutorials on doing exactly this and it seems to be very straight forward. I'll end up seeing the value 'live' as it is polled, inside the Arduino IDE.
The project is to use a web browser to build a small GUI around this measuring.
And therein lies my question:
How do I get this value to my browser?
First thought was that it's probably easy to set up some Websocket server on the Arduino and expose it on the computer it is USB connected to.
But when trying to find info on that, there seems to be a module ESP32 - which I think is a wifi/bluetooth module - that is required for that to work.
While wifi will not be reliable for the scenario (at least not until tested and proven successful, as a second resort), this makes me wonder if it's absolutely necessary to get values out of the Arduino?
Is it possible to send data from the Arduino to some network port or similar?
I just want to read the weight value with fairly high refresh rate (preferable 5 times per second or more if possible), in real time, over the network somehow. So I can display it in my browser.
PaulRB:
Simplify! Forget the Uno, use an esp board like Wemos Mini or an ESP32 board. No computer needed, the esp can host the web page itself.
Ok so I use an ESP32 instead of Arduino? First I thought ESP32 was an 'extra' module to add wifi etc.
Can I still connect over USB though?
Maybe I'm not seeing the full picture, but sorting out hosting the webserver on the ESP itself sounds like the opposite of simplification.
If I need to update files on the server, I guess it's a more cumbersome process?
No, esp are fully-fledged development boards. You can use them as add-on WiFi boards to an Uno, yes. But that's like pulling a Ferrari along, with a donkey. An Uno has a single, 8-bit, 16MHz CPU core, 2KB ram and 32KB non-volatile memory. Yes, that's megahertz and kilobytes, not gigahertz and megabytes! An esp has 1 or 2 32-bit cores running at 80 to 320 MHz with at least 48KB ram and 1MB non-volatile memory.
As previously mentioned, get one of the WeMOS wifi development boards and run a web server on it. They have some of the I/O functionality of the UNO, as well as room for on board file storage. Use the UNO as a slave if needed. I got a couple of the below development boards and they work ok with no issues so far. If you live in the US, they have about a 5 day delivery time.
Ok the Wemos D32 Pro seems like a solid choice. It's not too expensive in this context either.
Do you know if it's possible to communicate between the Wemos board and a computer over USB - other than when debugging/flashing etc?
I know and understand the fact that it has wifi, and that's great and all.
But what if I want to access the web server for example, via wire? Or rather, the real time value of my load cell.
A web server doesn't help me if it's about serving static files. I can do that sort of wherever in my scenario, and doing it on a microcontroller would only serve to make the situation more complex.
Are you saying that the real time value of my load cell, which is my no 1 priority, can also be served over the web server?
If you mean can the Wemos join the network over USB, I don't know. The esp chips don't have a native USB interface and rely on a USB-serial adaptor chip, which limits the speed to 115200 baud or maybe higher, which if fine for upload & debugging, as you said. But if it can join the network somehow over USB/serial, you won't be able to debug using serial at the same time, I would imagine. This isn't something I've ever looked into.
What I don't get is why you are so concerned about connecting to the network over wire?
As for static vs. dynamic pages, on a full-size server, you would use some scripting language such as PHP to dynamically create the page on request. Arduino/esp32 can't run PHP, but of course you can do the same thing in C/C++. Not quite as convenient, but principally the same. ESP have a flash-based file storage utility called SPIFFS, which you can use to upload the static part of the web page. The C code can then read that and add in the dynamic parts.
How would you normally approach this, as a web developer?
Do you need the page, or part of it, to update 5 times per second, or would one update per second be enough as long as 5 data points from each second are shown in the results?
your web server can access the com port of the computer it runs on and then put the value in the generated page or serve it over AJAX.
a simple Arduino like a Nano can send you the sensor data over a com port
I think the easiest way to describe my thought process here is to answer your question on how I would approach this as a web developer.
PHP is no problem for me, I work with that daily.
The application here is using a laptop to display and interact with the weight values hanging from a load cell.
So, my initial thought was, if I can just figure out how to measure the load cell with an Arduino/etc (so I found the HX711 chip being vital here), and get this value somehow to the laptop, then the rest is just easy peasy for me.
Preferably 5 times updated per second, rather than one update per second with 5 datapoints.
If I could get the real time value over a web socket server then everything is solved for me basically. I know how to do the rest.
Perhaps I'm missing something basic here, but currently I can't see the solution in front of me with what I've got so far. I don't know how to get the weight value from a microcontroller to a computer.
It'll probably be easier once I buy a few boards and experiment, but I was hoping to buy correct from the start and not go down dead ends.
Regarding wifi - Wifi for me is just another layer of potential problems. The use case here is on stage in front of people, and it's preferably a case where one could just plug stuff in and get going without any potential problems. Like waiting for wifi to connect.
Perhaps there wont be any problem at all (famous last words huh?). I just know from experience to simplify is to make things robust and less troublesome.
Perhaps this is the only simple solution? I'm not used to microcontroller world and this is probably a common solution.
Juraj - you mention com ports on the computer it runs on. Are you talking about the case where I use a web server on the microcontroller only?
Are we talking the old style com ports that look like VGA outputs? In this case the computer will be a modern laptop sadly lacking those ports
Waiting for WiFi to connect is usually less than a second. Of course you did test this out before you got on stage, to make sure you have the network name and password all set up correctly.
Plugging in a wire, takes about the same time - but now you have to make sure there's a wire available to connect to in the first place. That may be a big problem in many venues, which nowadays are not normally prepared for anyone to even be able to connect to a wire, let alone wanting to.
Mind: the ESP8266 and ESP32 can not only connect to an access point as station, they can actually BE the access point (so your phone can connect as client to your ESP module), and even take up both roles at the same time! Very convenient, and in my experience works really well.
tacklemcclean:
Juraj - you mention com ports on the computer it runs on. Are you talking about the case where I use a web server on the microcontroller only?
Are we talking the old style com ports that look like VGA outputs? In this case the computer will be a modern laptop sadly lacking those ports
you connect the Arduino to USB port of the laptop. it creates a virtual COM port (tty on Linux). and the Arduino can send data over this COM port very simple. to test the output can be read with Arduino Serial Monitor or with any other serial terminal program.
the web server running on the laptop has access to the COM ports of the laptop. it can read the values the Arduino sends.
"Perhaps I'm missing something basic here, but currently I can't see the solution in front of me with what I've got so far. I don't know how to get the weight value from a microcontroller to a computer.
It'll probably be easier once I buy a few boards and experiment, but I was hoping to buy correct from the start and not go down dead ends."
Yea, you need to get some boards and start experimenting with them so you can have a better idea of how things work. In its simplest form, you have the board read your module (I have no idea of how it works) and print the obtained value to the serial monitor 5 times a second. As to a web page display, I've used a main web page with a meta refreshing value display page in an iframe in the main page. It refreshed fairly quickly when the refresh value was set to 0. Below is a link to various ways to display data in a web page.