Why does Raspberry Pi need an OS to work? - python

I am just new to world of electronics. I was just looking about Raspberry Pi as I want to work on it, but a thing that I found that everyone is installing an OS first on the Raspberry Pi. I have worked upon PICs(16f) and Arduino board and it doesn't need that I just write a code and make burn on the board Can I do this with the Raspberry Pi?
Can't we just use an IDE to program the Raspberry Pi in python rather than installing an OS? Please explain if I conclude something wrong about the Raspberry Pi.

Long story short, the Pi is too complex hardware-wise to operate without an OS (for the vast majority of tasks, anyway).
An operating system is essentially an environment for your program to work in. It provides standardized means to use and manage hardware, interrupts, storage (incl. filesystems), I/O etc. What is more inportant, it does all the non task-specific heavy lifting in those tasks. So, you yourself only have to implement task-specific logic.
Without an operating system, you'll have to include all that functionality (or rather, the part of it that your task-specifc logic needs) into your program (that is called a "bare bones" programming environment). If the hardware is simple and unified enough (e.g. a specific model of a microcontroller), that it easy enough. But if the task of operating the hardware is complex enough and/or you need to support many different hardware configurations, it simply becomes too taxing to implement all that by hand each time.
For example, you said you'd like to write your program in Python.
A Python program doesn't exist in vacuum. It's run by a Python interpreter -- that needs to already be installed on the system so that you can feed your program to it. Likewise, the interpreter itself is written for a specific environment. E.g. CPython uses the C standard library. That library in turn may delegate work to whatever environment it is written to work in -- e.g. system calls of a specific OS. Finally, the OS, run by the system's CPU, interacts with peripheral devices in whatever ways the specific hardware environment is designed to (I/O ports, memory-mapped I/O, various standardized I/O protocols (like SATA) which typically consist of reading and writing hardware registers in devices and handling interrupts from them and the CPU itself; large data transfers are nowadays usually done with DMA, a session of which the OS logic still needs to set up.)
So if you're going to work without an OS, you'll need to implement any of those layers yourself first that would work in a Pi bare bones environment -- all just to run a simple Python program. You can take a look at Raspberry Pi Bare Bones - OSDev Wiki to get an idea of what that experience is like.

Raspberry pi basically is a computer. It's not a microcontroller so it's different with arduino. To do the microcontroller stuff with raspberry-pi all you need is wiringpi module you can download it freely. But raspberry pi is bigger than microcontroller so, it is wise that it used to controlling multiple microcontroller.

Raspberry pi is more complex, with a microprocessor, memory and GPU. Its like a full fledged computer, basically it needs a OS to managed everything unlike micro controllers like Arduino.

Related

Where to to put ts2591.mpy so that raspberry pi can utilize lux sensor

First Post, so please be gentle.
I am trying to run a lux meter on a raspberry pi 3 B+. The lux meter is Ts2591, that according to adafruit can be run by installing circuit python files. I have been following the instructions and am having trouble with where to put the ts2591.mpy file. I assume .mpy stands for python module. The website states to place it in the lib file. I have placed in in the python 3.7 lib file and the raspberry pi lib file, but I keep getting a 'cannot find module' error. If it turns out it has to go to a root file system, I am not sure where that is. I don't see a way to ask adafruit directly.
Here is the phrasing from the web site:
Before continuing make sure your board's lib folder or root filesystem has the adafruit_tsl2591.mpy, and adafruit_bus_device files and folders copied over.
The Adafruit ts2591 library is meant to be used with CircuitPython, (which is like a fork of MicroPython). Both CircuitPython and MicroPython have built-in support for the hardware generally found on microcontrollers, like the UART, I2C and SPI communication buses and things like ADC's and switching hardware pins on and off.
Out of the box, this code won't work with "standard" python. For one thing, regular Python doesn't have built-in I2C support. The raspberry pi has Python modules to support its special hardware, but those are different (have a different API) from the ones in CircuitPython.
Basically you have a couple of options.
You can use the adafruit blinka compatibility layer and then the adafruit_tsl2591 module.
You can port the tsl2591 code to run on the raspberry Pi. Luckily, this has already been done: maxlklaxl/python-tsl2591. Download that from github or pypi.
In general, since you can read the CircuitPython code, porting that to another platform with another I2C library isn't too hard.

How to embed machine learning python codes in hardware platform like raspberry pi?

I want to implement machine learning on hardware platform s which can learning by itself Is there any way to by which machine learning on hardware works seamlessly?
Python supports wide range of platforms, including arm-based.
You raspberry pi supports Linux distros, just install Python and go on.
First, you may want to be clear on hardware - there is wide range of hardware with various capabilities. For example raspberry by is considered a powerful hardware. EspEye and Arduio Nano 33 BLE considered low end platforms.
It also depends which ML solution you are deploying. I think the most widely deployed method is neural network. Generally, the work flow is to train the model on a PC or on Cloud using lots of data. It is done on PC due to large amount of resources needed to run back prop. The inference is much lighter which can be done on the edge devices.

How can a python script detect whether headphones/earphones are connected to the pc or not?

I want to write a python to give a warning if I try to play music without headphones/earphones plugged in. How can I detect whether they are connected or not?
Modern Linux systems use dbus messaging system to communicate between application. You can manipulate existing objects (that means: other running software) or you can listen to some signals telling about changes in the system (screen locked, USB driver inserted, headphones plugged in, etc). Depending on the interface provided by system components (to be exact: mostly by your desktop manager components) you can also ask about current state. You can use dbus-python library to communicate with dbus from python. That's the software development part.
What you need to find is the answer to question: how to ask desktop manager using dbus about the state of connected peripherals like headphones. There is a chance it is documented somewhere on freedesktop website. They aim at standardize the way components communicate with each other. So, there is high chance your solution would be desktop manager independent. However, if you decide to ask this question on some forum, please do not forget to mention your desktop manager (kde, gnome, etc). BTW, I'm not certain is such question would be on-topic here, on Stack Overflow, but Ask Ubuntu shall be fine.

Implement A2DP sink on linux system using dbus-python api

I want to implement a custom A2DP sink on my linux system running the latest Ubuntu 12.04 with the latest bluez stack.
My Basic Requirements are:
Linux system to act as a receiver(like a bluetooth headset with automatic authentication with default key "0000" or "anything")
I want to use dbus-python API to communicate with bluez stack. I want to run my own algorithm to configure communication parameters in runtime, thats y i want to implement my own sink.
later i also want to implement HSP and HFP profiles for my linux system.
Basically, I want to run these profiles and test the external bluetooth module which is connected via usb with my linux system for various audio transmission configurations and evaluate the performance under different profiles for audio reception.
I know there must be open source code already available in the web. But i couldn't find one. Even if the code is written in C or JAVA it doesn't matter for me. I require it for my educational purpose and I cannot buy commercial codes. So, people with expertise kindly help me out in creating this test bed. Because, my main objective is to modify bluez stack in future and I dont want to waste time in creating the test bed.

Python or Lua - Realtime application

I have started using Python in a real-time application (serial communication with to gps modules at once), but have found out recently about Lua. Which language would be more suited to the application?
My definition of real-time in this context is the fastest possible time to receive, process and output the data. (Feedback system)
Both are fine languages. Neither should take you years to learn. An easy way to make the decision is to look at what modules are out there already.
For example, you mentioned that your application is related to GPS. Take a look at what libraries are already written to hook Python and Lua into your particular GPS hardware. Maybe someone's already done most of the hard work for you. If not, then go down a step. If you're talking to your GPS over an I2C link, look at I2C libraries in both languages. See which ones are more popular and better maintained.
That said, garbage collected languages have historically had problems with meeting real time requirements. Depending on yours, you may need to go with a lower level language. You should also ensure that whatever system you're running on will support your programming environment. I've worked with systems where Python would have been great but it doesn't fit in 5K of code space.
Take a look at eLua and see if it meets your needs.

Categories