element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Sci-Pi Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Sci-Pi Design Challenge
  • More
  • Cancel
Sci-Pi Design Challenge
Blog Pollinator Pollster, Part 7: Up and Running
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Sci-Pi Design Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: soldering.on
  • Date Created: 29 Jun 2023 6:42 AM Date Created
  • Views 1383 views
  • Likes 8 likes
  • Comments 9 comments
  • audio classification
  • fast fourier transform
  • pollinator pollster
  • sci-pi design challenge
Related
Recommended

Pollinator Pollster, Part 7: Up and Running

soldering.on
soldering.on
29 Jun 2023
Pollinator Pollster, Part 7: Up and Running

Pollinator Pollster

This is going to be a technically-focused blog, walking through each major system element in the detection process, which I wanted to cover in detail now that the prototype sensor is 'live' and installed in the garden for data collection trials. I'm going to discuss the pipeline from pollinator detection to the posting of data on the Pi 4 hosted web site to demonstrate the functioning of the system. There will be one final blog post after this, in which I'll share the domain name at which you will also be able to access this site and see the functioning of the sensor yourself.

Project Plan

The last time posting the project plan; at this point in time the full system prototype has been brought together, and is now deployed outside, so therefore over the next few days will validate the function of the power system, detection algorithm, and radio system. It has been a very busy few days getting it this far!

image

Deploying the Sensor

image

Here's the sensor pictured outside where it will remain from now! It has sprouted a little electrical tape around some of the major joins - although it passed the 'rain test' (garden hose) as you'll remember from the previous blog post, I want to be absolutely sure that no stray raindrop puts a stop to the final testing. There are plenty of plants in flower nearby and a lot of insect traffic, so plenty of opportunities to test correct detection.

Now, let's step through the sensor process which it will be running:

Step 1: The Microphone Detects the Bee

As mentioned before, for the prototype of the system I am using the 'Buff-Tailed Bumblebee', Bombus terrestris, a species I commonly see in my garden, as the example. The microphone, a Sparkfun Analog MEMS microphone, picks up the sound of the bee, perhaps as it visits a nearby flower.

Step 2: Fast Fourier Transform

The incoming audio data (in analog form from the microphone) is then received by the Raspberry Pi Pico for processing. At this stage, the C++ code applies a Fast Fourier Transform (FFT), a method which converts the audio signal from being mapped against the time domain to against the frequency domain. From this, it can be determined the frequency distribution of the data, and also the dominant frequency (the frequency with the greatest sound intensity). The code to do this on the Pi Pico was developed by Alex Wulff (see his blog on hackster 'ADC Sampling and FFT on Raspberry Pi Pico') which I employ to deliver the maximum frequency component.

There are three parameters within Alex's code which can be tuned to adapt the performance of the FFT to specific purpose. I iteratively tested these values with the Pico, whilst using a tone generator app on my phone to create test signals which could be analysed. Those parameters were:

  • CLOCK_DIV: The Pi Pico's RP2040 chip has two 'Phase-Locked Loop' circuits, which generate a 48MHz clock signal. The CLOCK_DIV variable divides that by the set number (optimum found to be 9600) into smaller divisions in order to reduce the sampling rate. 48,000,000 / 9,600 = 5,000Hz. The reason for doing so is we aren't interested in higher frequencies than this, so we can focus on the lower range, with greater resolution.
  • FSAMP: this needs to be set to the sampling rate to match CLOCK_DIV, so in this case 5000 (Hz).
  • NSAMP: this defines the number of samples which will be used for the FFT analysis. A higher value results in greater resolution and detail of the frequency spectrum, but is slower to calculate. A value of 2000 for this was found to be a good compromise, resulting in a frequency resolution of 2.5Hz (adequate to determine if the dominant frequency detected is that of a bee or not), and a satisfactorily fast sampling rate.

I've included a short video below showing testing of the FFT code using a tone generator app, and then 'in the wild' of my garden and the local park, collecting audio samples from bumblebees to determine what the detection criteria should be.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Step 3: Detection Algorithm

Now the FFT code has assigned the dominant frequency within the processed sample to the max_freq variable, the below snippet shows how that is handled. Firstly, to help with debugging and testing, the max_freq value is printed to the Serial. I used this (as shown in the above video) to determine that a dominant frequency of 37.5Hz is observed when this species of bumblebee is present next to the sensor.

Secondly, an if statement is used to determine if the max_freq value falls within a set range. As mentioned above, I believe that a dominant frequency of 37.5Hz indicates the presence of this bee species, hence a range of 35 to 40Hz is used as the test. I use a range rather than an ==37.5 test, as I may need to adjust the lower and upper bounds of this range if it seems I am getting false negatives or false positives.

If the max_freq value passes this test, the detection variable is set to equal 1. This variable is used as a latched test of whether or not a bee has been detected within this time window (see the next step). The variable can only be set back to 0 when this data is sent, hence if a bee is detected within the 5 minute window the detection variable will remain equal to 1, indicating a positive detection. This approach is used (rather than reporting how many detections occurred within the time window, as an individual bee may be detected multiple times, and that would lead to a very misleading count. Instead, the code as is will show at which times of day, and on which days within the year bees are active (in the vicinity of the sensor), an approach which I think would be more useful to a researcher.

image

Step 4: Data Transmission

The next step of the process is to get that data out of the sensor and to the hub! The code snippet below is a section of the C++ code running on the Pi Pico which handles this operation, so let's look at that in more detail.

image

At the start of the code snippet, the clock function is used to create a variable called 'elapsedTime'. This is a measure used to create an interval of 5 minutes (or 300 seconds), which is tested for in the first if statement. The purpose of this is to trigger data transmission at 5 minute intervals (rather than constant transmission). The nested if statement then determines whether the HC-12 transceiver sends a '1' if there has been a detection within the previous 5 minute window, or a '0' if not.

Before concluding the if statement, the detection variable is reset to 0, and the startTime variable is now set to match the last endTime variable. This will ensure that the elapsedTime variable is reset to 0 again, and therefore starts again counting up to 300 seconds at which point the next transmission will be triggered.

Step 5: Data Reception

In Part 3 of this blog series I described using an Arduino to program the HC-12 transceivers. They have their own microcontrollers and memory, and hence will remember the parameters (which define frequency, power, and operating mode) that they are programmed with. Both HC-12 units I purchased were programmed (using my trusty Arduino MEGA) to have matching settings, which also complied with UK radio spectrum laws.

With the HC-12 transceiver for the Pi 4 hub therefore, it was just a matter of getting it plugged in (using the same GPIO pins that I had tested with the Pi 3B in Part 3), and then revisiting the Python program I had created at that point. Sidenote: I was using the Pimoroni Fan Shim with the Pi 4, which is controlled using the UART pins, and although it shouldn't interfere with the operation of anything else connected to the GPIO pins, it turned out to block the function of the HC-12 entirely. This drove me round in circles for a while until I realised this issue wasn't code-based!!

The Python program for the Pi 4 needed minor adaptation to write the incoming data to a .csv file and not just print the results to serial as it had done previously. In addition to outputting the [1/0] signifying detection or not detection, it also appends to each line in the .csv file an output of the time function to give each data line a datetime stamp. This will be essential when it comes to processing the results in the next step!

Step 6: Graphing and Publishing

The data from the sensor has been received by the Pi 4 hub, and saved into a .csv file. Next, a separate process is needed to change this data into the right form to present on the Pi 4-hosted web site, so that a researcher can view the data from anywhere at anytime.

After trialing a few options, I decided to use a separate Python program on the Pi 4, along with matplotlib, to graph the data directly from the .csv file, and save this as an image, which can then be picked up by the HTML files serving the Flask app which runs the server.

I will be sharing the web domain in my next and final post, but for now here's an example chart I made (using dummy data) while developing the Python program and experimenting to see what the most effective type of chart might be.

image

Until Next Time

As always, thank you very much for reading my posts, I have been enjoying your updates this past week too, I hope I can count myself among those who have finished their projects soon. Good luck with your final steps if you're also finishing things off like me, and see you next time!

  • Sign in to reply
  • beacon_dave
    beacon_dave over 2 years ago in reply to soldering.on

    I've posted some photos of the bees on the Alliums today. It was a bit windy but there were about 15 bees active at any one time.

    /challenges-projects/design-challenges/save-the-bees-design-challenge/b/blog/posts/saving-the-bees-old-style

    If attempting a vision project then I would recommend using some sort of support structure to stop them swaying about in the wind. I've got short canes in but it is nowhere near enough.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 2 years ago in reply to soldering.on

    I started out with some of the Greenbrokers 'bee and butterfly' Spring and Summer 200 bulb promo packs in an attempt to get a bit of a variety going to see if I could attract more bumblebees. The Allium Sphaerocephalon was an instant hit, so have tended to stick with packs that contained them as I know they 'just work'. I have about 80 starting to flower at the moment and the bumblebees are already on them. I see that the RHS do landscape packs of 1,000 bulbs so that might be a summer project. It sounds a lot but the thin stems really need a lot of neighbouring flowers to help support them, and it would fill out a border quite nicely. They might tend to last a bit longer as the first time round the bees assaulted them and they were done and dusted within a few days.

    This year I removed some 20year old old shrubs that bees weren't particularly interested in and planted some heavy-flowering Fuchsia (Mrs Popple / Deltas Sara varieties) and they are already attracting bees in their first year (barely off the ground) so should be interesting when fully established in 5 years time. I planted some Salvia but unfortunately they haven't done anything this year. Lastly I planted a couple of climbing roses (Paul's Scarlet) to cover an old wall so hopefully in a few years time that will produce loads of bee friendly flowers. One is about to flower so I may get an indication of bee interest.

    So its been interesting to see the recent bee projects here on e14.

    I've seen a few interesting documentaries by Marcus du Sautoy and also have his Music of the Primes book. He comes across as the sort of maths teacher you wished you had at school.

    There was a recent discussion on here about insect homes and how a lot of the 'bee hotels' are potentially too shallow in depth for solitary bees. They may be slightly easier to monitor with a camera based system though as you are likely to get individual bees to individual holes. Their turnaround manoeuvre captures them from different angles so helps with identification.   

    There is a researcher here who made artificial bee nests to bury into the ground. They are equipped with a webcam for remote monitoring.

    https://inews.co.uk/news/environment/bees-bumblebee-nesting-pollinator-queen-bee-gardening-wildlife-1173809

    The book sounds like an interesting read. Will have to look out for a copy. I'm currently reading Helen Czerski's 'Blue Machine'.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • soldering.on
    soldering.on over 2 years ago in reply to beacon_dave

    Sorry for the slow reply it has been a busy few days! That's really interesting what you have observed with your bees, thank you for giving the details. Good to know about the Alliums too, we have been trying to plant with bees in mind so perhaps that will be our next thing to add!

    I really like Marcus du Sautoy, I bumped into him once in Bristol which was quite fun, but I haven't seen that documentary so thank you very much for linking, I will enjoy that.

    We see quite a variety of different bees and have noticed some solitary bees are now overnighting in the garden, saw one this morning sleeping wrapped up inside a strawberry plant leaf, so our next step is to build some insect homes and see if we can help establish a bit of a larger population like you have.

    In awe with bees generally, based just on the group behavioural and navigational aspects you mention, without even getting into their flight physics (the classic thing of for decades many aerodynamicists argued how on paper bees shouldn't be able to fly). I'd recommend a book 'The Simple Science of Flight' by Henk Tennekes, which I read last year, it tries to apply common aviation principles to the natural world and extend that into manmade flying machines, some quite interesting conclusions ...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 2 years ago in reply to beacon_dave

    "...I think it was one of Hannah Fry's maths/data ones ?..."

    Ok, wrong presenter, it was Marcus du Sautoy, not Hannah Fry

    'The Secret Rules of Modern Living Algorithms' 

    https://youtu.be/kiFfp-HAu64?t=2169

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 2 years ago in reply to soldering.on

    One year a mass of tree bumblebees moved into one of my compost bins. Opened the back door to discover  I was about to walk into around a hundred of them doing their orientation thing outside the newly claimed nest and then one-by-one disappearing into a gap at the bottom of one of the compost bin. They have returned year-on-year to the same compost bin but this year they have set up a nest in the house, flying in and out through an air brick.

    They don't like vibration so tapping the side if the compost bin would result in a strong audible response so you could tell if they were still occupying it or not.

    By chance, I found that they go mad over Allium Sphaerocephalon 'drumstick' plants, so I have been increasing the number of them in the front garden year-on-year. They have just started to come into flower here and am already seeing a number of bees active on them. Each plant has a thin stalk and a bulbous head which is covered in tiny flowers and the bees will land on one, spend some time checking each of the tiny flowers then move onto the next one and so on then return to base. It will depend on the species of the bee however as their proboscis feeding tube needs to be long enough to reach into the tiny flowers. I have another species that prefers to visit some new Fuchsia plants and there they will climb right up and disappear into the flower.

    They are difficult to count and track unless you have some means of identifying them. When they are feeding or doing their orientation thing then you can get a rough count but can't tell how many are in the nest. Sometimes they will have a damaged wing tip or worn patch of hair so you can identify an individual bee if they stay still long enough.

    I saw a documentary (I think it was one of Hannah Fry's maths/data ones ?) where they numbered and tracked them and they discovered that they had a way of solving 'the travelling salesman' maths problem, which allows them to visit the most flowers using the shortest route to conserve energy.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube